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

Notify task when resetting a Delay to a time in the past #2290

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

thomaswhiteway
Copy link
Contributor

If a Delay has been polled then the task that polled it may be waiting
for a notification. If the delay gets reset to a time in the past, then
it immediately becomes elapsed, so should notify the relevant task.

Motivation

Under certain conditions DelayQueue may update the current deadline to be in the past. The delay would immediately transition to elapsed, but wouldn't notify the appropriate task so the scheduler would never re-poll it.

Solution

When resetting the time on a Delay, if the Entry is transitioning into ELAPSED state call the waker to wake any registered task.

tokio/src/time/driver/entry.rs Outdated Show resolved Hide resolved
tokio/tests/time_delay_queue.rs Show resolved Hide resolved
@kleimkuhler
Copy link
Contributor

Just a heads up that CI uses this rustfmt command: rustfmt --check --edition 2018 $(find . -name '*.rs' -print). Should be good when that passes.

Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

Looks good.

@kleimkuhler
Copy link
Contributor

@thomaswhiteway If you can fix the merge conflict on this it should be good to go. Sorry this has not merged yet!

@jonhoo jonhoo added A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. E-finish-line M-time Module: tokio/time S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. labels Apr 17, 2020
If a Delay has been polled then the task that polled it may be waiting
for a notification.  If the delay gets reset to a time in the past, then
it immediately becomes elapsed, so should notify the relevant task.
Copy link
Contributor

@kleimkuhler kleimkuhler left a comment

Choose a reason for hiding this comment

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

Thanks!

@Darksonn Darksonn merged commit 947045b into tokio-rs:master Apr 29, 2020
@Darksonn Darksonn removed E-finish-line S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. labels Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-enhancement Category: A PR with an enhancement or bugfix. M-time Module: tokio/time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants