-
Notifications
You must be signed in to change notification settings - Fork 20.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eth/filters, eth/tracers: add request cancellation checks #26320
Conversation
This ensures that RPC method handlers will react to a timeout or cancelled request soon after the event occurs.
5649ee3
to
eacf53d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
eth/tracers/api.go
Outdated
case jobs <- task: | ||
case <-ctx.Done(): | ||
failed = ctx.Err() | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Classic mistake here, break
here will terminate the select
instead of enclosing loop.
for i, tx := range txs { | ||
// Send the trace task over for execution | ||
jobs <- &txTraceTask{statedb: statedb.Copy(), index: i} | ||
task := &txTraceTask{statedb: statedb.Copy(), index: i} | ||
select { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this more efficient than simply checking ctx.Err()
at the beginning of the loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not more efficient, I just did it because the send could theoretically block at this point. Canceling the context would unblock it. However, it seems the jobs
channel is actually buffered, and so the send will always succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…6320) This ensures that RPC method handlers will react to a timeout or cancelled request soon after the event occurs. Co-authored-by: Sina Mahmoodi <[email protected]>
This ensures that RPC method handlers will react to a timeout or cancelled request soon after the event occurs.