Skip to content

transport: close TCP connection on any stream framing error - #345

Open
Mliviu79 wants to merge 2 commits into
emiago:mainfrom
Mliviu79:pr/tcp-framing-close
Open

transport: close TCP connection on any stream framing error#345
Mliviu79 wants to merge 2 commits into
emiago:mainfrom
Mliviu79:pr/tcp-framing-close

Conversation

@Mliviu79

@Mliviu79 Mliviu79 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #344

Stacked on #324, which makes parseStream return an error at all — on main it returns nothing, so readConnection cannot react to a parse failure. Please take that first — the diff here is only the widened condition plus a test on top.

Mliviu79 added 2 commits July 19, 2026 10:14
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.
@emiago

emiago commented Aug 7, 2026

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

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.

sip: the TCP read loop continues after a framing error and grafts the next request onto the failed one

2 participants