Repository navigation
Conversation
When the CloseRead goroutine reads a data message it calls Close, and Close waits for that same goroutine to exit. The wait ended only on its 15 second timeout, so the CloseRead context was cancelled 15 seconds late and a concurrent Close stalled for as long. The goroutine now runs the close handshake itself. When another Close is already running, it waits for that Close to close the connection, because exiting earlier closes the connection before that Close has finished its handshake.
This branch has not been deployed
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.
When the
CloseReadgoroutine reads a data message, it callsClose, andClosewaits for that same goroutine to exit. That wait ends only at its 15 second timeout, so the contextCloseReadreturns is cancelled 15 seconds late. AClosethat the application calls in that window also waits about 15 seconds. If it starts before the goroutine's own wait, it then returnsfailed to close WebSocket: failed to wait for close read goroutine to exit.The goroutine now runs the close handshake itself instead of calling
Close, and its deferredclosecloses the connection. If anotherCloseis already closing the connection, the goroutine waits until thatClosehas closed it.TestCloseReadDataMessage/closesConnandTestCloseReadDataMessage/duringClosefail on master and pass here. They run in atesting/synctestbubble, so a close that waits on the 15 second timer fails the test without waiting for it. Lint,go test -race ./...on Go 1.26 and 1.27, and the Wasm tests pass.This conflicts with #564 in the
CloseReadgoroutine inread.go, where #564 replaces the sameClosecall with an internal close. Whichever merges second needs a rebase that keeps this change's handshake.Decision log
Close, becauseClosewaits for theCloseReadgoroutine to exit.Closeis closing the connection, the goroutine waits forc.closedinstead of returning. Returning runs the deferredclose, which would close the connection before thatClosehas finished its handshake.StatusPolicyViolationand "unexpected data message".Closecall was.Closewaits for the browser's close event, not for theCloseReadgoroutine.