fix(audio-transform): serialize WebSocket writes to avoid concurrent-write panic - #10857
Merged
richiejp merged 2 commits intoJul 16, 2026
Merged
Conversation
…write panic AudioTransformStreamEndpoint writes to the same Gorilla WebSocket connection from two goroutines: the backend-forwarding goroutine emits binary PCM frames (and can call sendWSError on a backend recv error), while the read loop calls sendWSError for malformed mid-stream JSON or a backend send failure. Gorilla WebSocket permits only one concurrent writer, so these writers race and can panic with "concurrent write to websocket connection", resetting the client session; a -race build reports the data race directly. Wrap the connection in a lockedConn that serializes WriteMessage behind a mutex, mirroring the existing lockedConn used by the openresponses WebSocket endpoint. Reads stay on the single read loop, so only writes need the lock. Fixes mudler#10844 Signed-off-by: Tai An <antai12232931@outlook.com>
Signed-off-by: Anai-Guo <antai12232931@anaiguo.com>
Collaborator
|
Reviewed this against issue #10844. Verification done:
CI is green and the branch is mergeable. @mudler this looks good to merge: it serializes all WS writes exactly at the two racing sites from the issue, with a compile-enforced wrapper and no behavior change otherwise. |
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.
What
AudioTransformStreamEndpointwrites to the same Gorilla WebSocket connection from two goroutines:ws.WriteMessage) and can callsendWSErroron a backendrecverror;sendWSErrorfor malformed mid-stream JSON or a backendsendfailure.Gorilla WebSocket permits only one concurrent writer. These two writers race, which can panic with
concurrent write to websocket connectionand reset the active client session. A-racebuild reports the data race directly.Fix
Wrap the connection in a
lockedConnthat serializesWriteMessagebehind a mutex — the same pattern already used by theopenresponsesWebSocket endpoint (core/http/endpoints/openresponses/websocket.go). Reads stay on the single read loop, so only writes need the lock. All existingws.call sites are unchanged becauselockedConnembeds*websocket.Conn(promotingReadMessage/SetReadLimit/Close) and overrides onlyWriteMessage.Fixes #10844
Notes
AI-assisted, human reviewed.
🤖 Generated with Claude Code