Skip to content

fix: multichunk reads#84

Open
SirBrucey wants to merge 1 commit into
djc:mainfrom
SirBrucey:chunked_reads
Open

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

Conversation

@SirBrucey

Copy link
Copy Markdown

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,
  })
}

@djc djc left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread tests/chunked_read.rs Outdated
Comment thread src/connection.rs Outdated
@valkum valkum mentioned this pull request Feb 20, 2026
@SirBrucey

SirBrucey commented Mar 16, 2026

Copy link
Copy Markdown
Author

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

@djc djc left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread tests/chunked_read.rs Outdated
use instant_epp::client::{Connector, EppClient};
use instant_epp::Error;

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

Copy link
Copy Markdown
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).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nits addressed and squashed.

@valkum

valkum commented May 29, 2026

Copy link
Copy Markdown
Contributor

I encountered this approx. at the same time and would have filed a PR fixing this if I had not found this PR at the time. Could we move this forward so I can drop my own fix.
If you want, I can take care of the remaining remarks next week. Just not sure about the best way to do so. Should I send you a patch, create PR with existing commits and mine on top, or something different?

@djc

djc commented May 30, 2026

Copy link
Copy Markdown
Owner

Send your own PR with a clean commit history, keep the author of this PR as author or co-author of commits where that makes sense.

@SirBrucey

Copy link
Copy Markdown
Author

I encountered this approx. at the same time and would have filed a PR fixing this if I had not found this PR at the time. Could we move this forward so I can drop my own fix. If you want, I can take care of the remaining remarks next week. Just not sure about the best way to do so. Should I send you a patch, create PR with existing commits and mine on top, or something different?

Apologies I missed the above response. I'll get those changes in today.

@valkum

valkum commented May 30, 2026

Copy link
Copy Markdown
Contributor

Apologies I missed the above response. I'll get those changes in today.

Thank you!

When EPP responses arrived in multiple chunks, the read counter would
reset to its previous value instead of accumulating, causing spurious
"Unexpected EOF while reading" errors.

The connection state machine's pattern destructuring copied state fields
instead of mutating them, so increments to the read counter were lost
when the original state was returned. Construct the next state with the
updated counter instead.

Adds test coverage for single and multi-chunk greeting reads.
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.

3 participants