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

Make DelayQueue wake the task at the right time after insert #2217

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

thomaswhiteway
Copy link
Contributor

If an entry is inserted in the queue before the next deadline, the
DelayQueue needs to update the Delay tracking the next time to poll.

If there is an existing Delay, reset that rather than replacing it as if
it's already been polled the task will be waiting for a notification
before it will poll again, and dropping the Delay means that that
notification will never be performed.

Motivation

In certain cases DelayQueue may not wake the appropriate task if it is modified after it's already been polled. This PR covers the case where an entry is being inserted before the current deadline.

Solution

When changing the deadline, if there's an existing Delay then update that rather than creating a new one as creating a new delay throws away the task registration.

If an entry is inserted in the queue before the next deadline, the
DelayQueue needs to update the Delay tracking the next time to poll.

If there is an existing Delay, reset that rather than replacing it as if
it's already been polled the task will be waiting for a notification
before it will poll again, and dropping the Delay means that that
notification will never be performed.
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Thanks!

@carllerche carllerche merged commit 7207bf3 into tokio-rs:master Feb 26, 2020
sthagen added a commit to sthagen/tokio-rs-tokio that referenced this pull request Feb 26, 2020
time: avoid needing to `poll` DelayQueue after insertion (tokio-rs#2217)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants