mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc: fix rare deadlock when canceling HTTP call context
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
This commit is contained in:
parent
c8c3ebd593
commit
3795269c7a
1 changed files with 5 additions and 3 deletions
|
|
@ -137,9 +137,11 @@ func (op *requestOp) wait(ctx context.Context, c *Client) (*jsonrpcMessage, erro
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
// Send the timeout to dispatch so it can remove the request IDs.
|
// Send the timeout to dispatch so it can remove the request IDs.
|
||||||
select {
|
if !c.isHTTP {
|
||||||
case c.reqTimeout <- op:
|
select {
|
||||||
case <-c.closing:
|
case c.reqTimeout <- op:
|
||||||
|
case <-c.closing:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
case resp := <-op.resp:
|
case resp := <-op.resp:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue