[SharovBot] fix: resolve WebSocket client deadlock on oversized message#20897
Open
erigon-copilot[bot] wants to merge 2 commits intomainfrom
Open
[SharovBot] fix: resolve WebSocket client deadlock on oversized message#20897erigon-copilot[bot] wants to merge 2 commits intomainfrom
erigon-copilot[bot] wants to merge 2 commits intomainfrom
Conversation
Fix a race condition in the RPC client dispatch loop that could cause TestWebsocketLargeCall (and real clients) to hang indefinitely. When a client sends a message that exceeds the server's read limit, the server closes the connection. If the client's write succeeds (data was TCP-buffered) while the read loop has already detected the closed connection, the in-flight request was orphaned: cancelAllRequests intentionally skipped it (to allow re-registration on reconnect), but no reconnect occurred because the write didn't fail. The request's resp channel was never closed, causing op.wait() to block forever. The fix detects this specific scenario in the reqSent handler: if the write succeeded (err == nil) but the read loop is already dead (!reading), the in-flight request is explicitly failed with errDead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
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.
Summary
dispatchloop that causedTestWebsocketLargeCallto hang indefinitely (deadlock)cancelAllRequestsskipped it (for potential reconnect reuse), but no reconnect happened, leavingop.respunclosed andop.wait()blocking foreverreqSenthandler: if the write succeeded but the read loop is dead, the in-flight request is explicitly failed witherrDeadTest plan
go build ./...passesgo test -race -count=1 -timeout 2m ./rpc -run TestWebsocketLargeCallpasses 10/10 consecutive runsgo test -race -count=1 -timeout 5m ./rpc/...full package suite passes🤖 Generated with Claude Code