Skip to content

Commit 8d815e3

Browse files
fjlkaralabe
authored andcommitted
rpc: fix rare deadlock when canceling HTTP call context (#19715)
When cancelling the context for a call on a HTTP-based client while the call is running, the select in requestOp.wait may hit the <-context.Done() case instead of the <-op.resp case. This doesn't happen often -- our cancel test hasn't caught this even though it ran thousands of times on CI since the RPC client was added. Fixes #19714
1 parent 3271a5a commit 8d815e3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎rpc/client.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ func (op *requestOp) wait(ctx context.Context, c *Client) (*jsonrpcMessage, erro
137137
select {
138138
case <-ctx.Done():
139139
// Send the timeout to dispatch so it can remove the request IDs.
140-
select {
141-
case c.reqTimeout <- op:
142-
case <-c.closing:
140+
if !c.isHTTP {
141+
select {
142+
case c.reqTimeout <- op:
143+
case <-c.closing:
144+
}
143145
}
144146
return nil, ctx.Err()
145147
case resp := <-op.resp:

0 commit comments

Comments
 (0)