[SharovBot] rpc: fix deadlock in client dispatch when connection lost during write#20898
Open
erigon-copilot[bot] wants to merge 2 commits intomainfrom
Open
[SharovBot] rpc: fix deadlock in client dispatch when connection lost during write#20898erigon-copilot[bot] wants to merge 2 commits intomainfrom
erigon-copilot[bot] wants to merge 2 commits intomainfrom
Conversation
When a WebSocket server rejects an oversized message (exceeding SetReadLimit), the connection is closed. If the client's read loop detects this closure while a write is still in-flight, cancelAllRequests intentionally excludes the in-flight request (lastOp) to allow a potential reconnection to re-register it. However, if the write completes successfully without triggering a reconnect, no reader exists to deliver a response. The excluded request's resp channel is never closed, causing client.Call to block indefinitely. Fix: when reqSent fires with a successful write but reading is false (no active reader), fail the orphaned request immediately with errDead so the caller doesn't hang. 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
Client.dispatchwhen a WebSocket connection is lost while a write is in-flightSetReadLimit),cancelAllRequestsexcludes the in-flight request (lastOp) to allow reconnection. If the write then succeeds without reconnecting, no reader exists to deliver a response, orphaning the request and causingCallto block forever.reqSentcompletes with no error butreading == false, the orphaned request is now immediately failed witherrDeadTest plan
TestWebsocketLargeCallpasses 10 consecutive times with-race -count=1 -timeout 2m./rpc/...package tests pass with-race -count=1 -timeout 5mgo build ./...succeeds🤖 Generated with Claude Code