transport: answer WS pings and read the control payload out of the stream - #326
Open
Mliviu79 wants to merge 1 commit into
Open
transport: answer WS pings and read the control payload out of the stream#326Mliviu79 wants to merge 1 commit into
Mliviu79 wants to merge 1 commit into
Conversation
…he stream A Ping carrying a payload left those bytes in the stream, so the next header read started mid payload and the following frame did not decode. Control frames are now handled with wsutil.ControlHandler, which answers a Ping with a Pong carrying the same payload, discards a Pong, and reads the payload out either way. RFC 6455 section 5.5. ws writes a frame header and payload separately, so a Pong written from the read goroutine can interleave with a concurrent WriteMsg and neither frame decodes. All frame writes now go through writeFrame under a mutex, and the write lock is held across the control handler. Refs emiago#325
This was referenced Jul 19, 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.
Fixes #325
A Ping carrying a payload left those bytes in the stream, so the next header read started mid payload and the frame after the ping did not decode.
transport_ws.go:409had the Ping arm commented out.Control frames now go through
wsutil.ControlHandler, which answers a Ping with a Pong carrying the same payload (RFC 6455 section 5.5.2), discards a Pong, and reads the payload out of the stream either way.That introduces a second writer on the connection.
wswrites a frame header and payload separately, so a Pong from the read goroutine can interleave with a concurrentWriteMsgand neither frame decodes. All frame writes now go throughwriteFrameunder a mutex, and the lock is held across the control handler.Tests cover a ping with a payload (asserting the following text frame still decodes), the empty-ping fast path, and 8 concurrent writers proving frames stay intact — the last one is meaningful under
-race.