transport: close TCP connection on any stream framing error - #345
Open
Mliviu79 wants to merge 2 commits into
Open
transport: close TCP connection on any stream framing error#345Mliviu79 wants to merge 2 commits into
Mliviu79 wants to merge 2 commits into
Conversation
The size limit was only checked once a message parsed in full, so a peer that never finishes one was never stopped. On the partial-parse path ParseNext now sums totalRead and the buffer length and returns ErrMessageTooLarge when that exceeds MaxMessageLength, discarding the buffered bytes: an unfinished message leaves no boundary to resync on. Neither pool is bounded alone. Complete header lines drain into the message and keep the buffer near empty while the message grows; a line that never terminates does the reverse. Only their sum bounds the peer. TCP closes the connection on ErrMessageTooLarge rather than reading on. Refs emiago#323
readConnection closed the connection only on ErrMessageTooLarge. Any other hard parse error - a message with no Content-Length returns ErrParseReadBodyIncomplete - left the parser dirty (ParseNext resets state only on success) while the read loop carried on, so the peer's next bytes were parsed as headers of the message that just failed: a stream desync. On a stream transport Content-Length is how messages are framed, so any parse error means framing is lost and there is no boundary to resync on; close instead. parseStream already maps an incomplete message (more bytes still coming) to a nil error, so this fires only on genuine framing failures. TLS inherits the behavior through the TransportTCP embed. Pre-existing, not introduced here (unrelated file transaction_server_tx_test.go): TestServerTransactionRespondRejectsCRLF panics with a nil pointer dereference in spinFsmUnsafe on the parent branch as well.
Owner
|
fix conflicts. but also pls tell your AI to make this comments in one sentence. Code should it self be clear enough to understand what is doing and not comments |
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.
Fixes #344
Stacked on #324, which makes
parseStreamreturn an error at all — on main it returns nothing, soreadConnectioncannot react to a parse failure. Please take that first — the diff here is only the widened condition plus a test on top.