Skip to content

fix: multichunk reads#84

Open
SirBrucey wants to merge 1 commit intodjc:mainfrom
SirBrucey:chunked_reads
Open

fix: multichunk reads#84
SirBrucey wants to merge 1 commit intodjc:mainfrom
SirBrucey:chunked_reads

Conversation

@SirBrucey
Copy link

When EPP responses arrived in multiple chunks, the read counter would reset to its previous value instead of accumulating.
This caused the code to think it hadn't read as many bytes as it actually had, leading to "Unexpected EOF while reading" errors.

2026-02-05T12:02:05.416810Z DEBUG: instant_epp::connection: Expected response length: 2539
2026-02-05T12:02:05.417597Z DEBUG: instant_epp::connection: Read 1172 bytes, 1428 out of 2539 done
2026-02-05T12:02:05.417637Z DEBUG: instant_epp::connection: Read 1111 bytes, 1367 out of 2539 done

The connection state machine's pattern destructuring creates copies of state fields instead of mutable references into the struct. When these were modified (e.g., incrementing read counter), the modifications were lost because the original state was returned.

Example:

RequestState::Reading { mut read, buf, expected } => {  // copies read
  ...
  read += filled.len();  // Modifies LOCAL copy
  ...
  Transition::Next(state)  // Returns ORIGINAL state with OLD read value
}

Fix: Construct new state objects with updated values:

RequestState::Reading { read, buf, expected } => {
  let new_read = *read + filled.len();  // Calculate new value

  // Return NEW state with updated counter
  Transition::Next(RequestState::Reading {
      read: new_read,
      buf: mem::take(buf),
      expected: *expected,
  })
}

When EPP responses arrived in multiple chunks, the read counter would reset to its previous value instead of accumulating.
This caused the code to think it hadn't read as many bytes as it actually had, leading to "Unexpected EOF while reading" errors.

```
2026-02-05T12:02:05.416810Z DEBUG: instant_epp::connection: Expected response length: 2539
2026-02-05T12:02:05.417597Z DEBUG: instant_epp::connection: Read 1172 bytes, 1428 out of 2539 done
2026-02-05T12:02:05.417637Z DEBUG: instant_epp::connection: Read 1111 bytes, 1367 out of 2539 done
```

The connection state machine's pattern destructuring creates copies of state fields instead of mutable references into the struct. When these were modified (e.g., incrementing read counter), the modifications were lost because the original state was returned.

Example:
```
RequestState::Reading { mut read, buf, expected } => {  // copies read
  ...
  read += filled.len();  // Modifies LOCAL copy
  ...
  Transition::Next(state)  // Returns ORIGINAL state with OLD read value
}
```

Fix: Construct new state objects with updated values:
```
RequestState::Reading { read, buf, expected } => {
  let new_read = *read + filled.len();  // Calculate new value

  // Return NEW state with updated counter
  Transition::Next(RequestState::Reading {
      read: new_read,
      buf: mem::take(buf),
      expected: *expected,
  })
}
Copy link
Owner

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for fixing this upstream and adding test coverage!

Would be curious to hear what/where you're using it.

use std::time::Duration;

use async_trait::async_trait;
use rstest::rstest;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of adding this new dependency with unfamiliar attribute macro stuff. Can you just write a few #[test] functions with maybe a simple helper function?

}

start += wrote;
let new_start = *start + wrote;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd prefer to just shadow the old binding, keeping it as start (here and below).

@valkum valkum mentioned this pull request Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants