Repository navigation
Fix stray compressed bytes before PROCEED on large messages - #730
Merged
Merged
Conversation
rhysparry
marked this pull request as ready for review
October 23, 2026 01:36
LukeButters
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
UsageFixture.LargeMessagessometimes fails on Windows/net48 because a stray byte appears in front of a control message, for exampleExpected PROCEED, got: \u001fPROCEED(LEV-2142, LEV-2098).The stray byte is left over from the previous message. For large messages, Halibut stops reading the compressed stream as soon as the message is complete. But the compressed stream can end with a byte or two that the message doesn't need. If those bytes arrive late, Halibut never reads them, and they're read as part of whatever comes next.
This is a bug in Halibut, not in .NET Framework. It affects all frameworks and older Halibut versions too, but it's rare. It only happens when those last bytes arrive in a separate network read. net48 likely hits it more often because of how its zlib splits its output, but we haven't confirmed that.
Results
After reading a message, Halibut now keeps reading the compressed stream until it reports the end. That consumes any remaining bytes before the next message is read.
If the compressed stream has more data after the message, Halibut now throws a
ProtocolExceptioninstead of ignoring it. Halibut never sends data like that.A new test reproduces the problem by delivering the last compressed bytes in a separate read.
Before
The new test fails, and the data after the message starts with a stray byte:
After
The new test passes, and the data after the message is
PROCEED.How to review this PR
Quality ✔️
MessageSerializer.ReadCompressedMessageAsync.Pre-requisites
🤖 Generated with Claude Code
🤖 Agent's description, endorsed by Rhys