Skip to content
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

Detect and return error on eth_call on timeout #19737

Merged
merged 1 commit into from
Jun 24, 2019

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Jun 19, 2019

This PR fixes #19186

Problem: on eth_call and derivates using the same mechansm, there's a timeout that can trigger at any time. We currently do not signal this to the user, thus returning erroneous values when execution is aborted.

This PR addresses thsi in a somewhat opportunistic way, since the timeout happens async in another goroutine. When we return from the actuall call, we check if the Cancel has been called on the evm. There is a tiny chance that the cancel was called after the execution finished correctly, but it's bettter to error on the safe side than how we do it now (and the chances of that happening are really quite slim).

Example when running this PR in geth --dev console, using an eternal loop (jumpdest; push 0, jump):

> eth.call({"gas":800000000000000000, "data":"0x5b600056"})
WARN [06-19|12:41:51.398] Served eth_call                          reqid=26 t=5.000339274s err="execution aborted (timeout = 5s)"

Without this PR:

> eth.call({"gas":800000000000000000, "data":"0x5b600056"})
"0x"

@holiman
Copy link
Contributor Author

holiman commented Jun 19, 2019

Might also close #19145

@@ -802,6 +802,10 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNr rpc.BlockNumb
if err := vmError(); err != nil {
return nil, 0, false, err
}
// If the timer caused an abort, return an appropriate error message
if evm.Cancelled() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess there's a tiny data race here, whereby it could happen that a call finishes successfully, but then the timeout triggers before this line and a failure is returned... but that seems both improbable and not an issue (it's like winning the lottery, would have timed out for real most of the time).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know:

This PR addresses thsi in a somewhat opportunistic way, since the timeout happens async in another goroutine. When we return from the actuall call, we check if the Cancel has been called on the evm. There is a tiny chance that the cancel was called after the execution finished correctly, but it's bettter to error on the safe side than how we do it now (and the chances of that happening are really quite slim).

Basically, the data-race is 'benevolent'. The worst that can happen is that it falsely says it was aborted, which is better than the other way around

@karalabe karalabe added this to the 1.9.0 milestone Jun 24, 2019
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants