Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #263 +/- ##
==========================================
+ Coverage 93.75% 93.93% +0.17%
==========================================
Files 73 73
Lines 4022 4042 +20
==========================================
+ Hits 3771 3797 +26
+ Misses 251 245 -6 ☔ View full report in Codecov by Harness. |
swhitty
force-pushed
the
websocket-handoff-followup
branch
4 times, most recently
from
November 15, 2026 22:04
0ad8d20 to
99ce2bc
Compare
… cancelled send was documented to throw CancellationError when the sending task is cancelled, but only checked while suspended. A cancelled sender could still hand its element to a waiting receiver or add it to the buffer.
Follow-up to #249: - Finish the handler's input once the task reading it is cancelled or the stream is released, and drop later client messages, so frames are still read and pings and closes still answered. Tests cover a handler that cancels while keeping its input, and one that releases it. - Keep the advice from #249: a handler that does not need the client's messages should still read and discard them, or now not keep its input at all. - Make capacity a public parameter of MessageFrameWSHandler.init and HTTPHandler.webSocket, as offered in #249. Its documentation notes that each waiting message can be as large as webSocketMaxFrameSize. - Only the frame loop ends the handler's input. Teardown could previously finish it first when the output loop ended, losing the close message. - Check the backpressure tests reach their expected counts, not only that they stay under them. - Cite RFC 6455 §5.5.1 for the close echo, and stop finishing the input with a Result that cannot fail.
swhitty
force-pushed
the
websocket-handoff-followup
branch
from
November 16, 2026 00:56
99ce2bc to
760d548
Compare
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.
Follow-ups to #249, in two commits.
AsyncHandoff.sendthrowsCancellationErrorwhenever the sender is cancelledsendwas documented to throwCancellationErrorwhen the sending task is cancelled, but only checked while suspended. A cancelled sender could still hand its element to a waiting receiver or add it to the buffer.Pings and closes are still answered once the handler stops reading
Since #249, once 16 client messages wait for the handler, the frame loop stops reading and TCP pushes back on the client, so pings and closes wait too. That is the intended backpressure while the handler is reading. But a handler that has stopped reading for good, such as a broadcast-only handler, held the connection back for messages it would never read.
AsyncStream(unfolding:)releases its closure in both cases, and the closure holds aHandlerInputwhosedeinitfinishes the handoff.capacityis now a parameter ofMessageFrameWSHandler.initand.webSocket(_:frameSize:capacity:), defaulting to 16, as offered in Bound the WebSocket frame and message buffers #249. Its docs note that each waiting message can be as large aswebSocketMaxFrameSize.Relation to #249
@lhoward, this changes code from #249, so I'd appreciate your review. What it keeps, adds and changes:
capacity.messagesInis no longer finished as soon as either loop ends; the frame loop finishes it when it is cancelled.framesOutis still finished right away, so the connection still closes when the handler's output ignores cancellation. Socket reads and handoff sends both respond to cancellation, so the handler's input still ends promptly.AsyncHandoff.sendto check for cancellation before handing an element off.Testing
sendthrowsCancellationErrorwhen cancelled with buffer space or with a waiting receiver.main. The WebSocket andAsyncHandoffsuites passed 30 runs in a row. Not run on Linux locally.🤖 Generated with Claude Code