make timeout robust against budget-depleting tasks #4314
Merged
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.
Refs: #4291 , #4300
Motivation
Up until now, if the future that we were applying a timeout to
consistently depleted the coop budget, the timeout never got a chance to
be evaluated. In the next call to
poll
, the underlying future would bepolled and it would once again deplete the budget. In those circumstances,
timeouts would not be respected. This can be surprising to people, and
in fact it was in #4291
Solution
The solution is to make a budget exception with
timeout
if it was theunderlying future that depleted the budget.
I guess there are still pathological cases where the budget is almost depleted
before polling the
delay
, and it gets depleted while polling the delay, resulting inthe timeout never being hit as well. How do we want to go about that? I could simply do:
instead of taking into consideration whether the underlying future depleted (or not) the budget.
Testing
I have added a test along the lines of the original #4291 issue.