Skip to content

fix: multichunk reads#84

Open
SirBrucey wants to merge 3 commits intodjc:mainfrom
SirBrucey:chunked_reads
Open

fix: multichunk reads#84
SirBrucey wants to merge 3 commits 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.

@valkum valkum mentioned this pull request Feb 20, 2026
@SirBrucey
Copy link
Author

SirBrucey commented Mar 16, 2026

Sorry for the delay, those fixes have been pushed up.

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

I am currently trying to use the library to talk to nominet

@SirBrucey SirBrucey requested a review from djc March 16, 2026 10:34
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.

Some minor nits, please also squash all of your commits.

use instant_epp::client::{Connector, EppClient};
use instant_epp::Error;

fn len_bytes(bytes: &[u8]) -> [u8; 4] {
Copy link
Owner

Choose a reason for hiding this comment

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

Okay, some minor remaining nits: please order these in top-down fashion; first the #[test] functions, then connect_with_chunks(). Suggest inlining len_bytes() and changing greeting to be a const (this should be at the bottom).

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