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

time: fix DelayQueue rewriting delay on insert after Poll::Ready #2285

Merged
merged 4 commits into from
Mar 26, 2020

Conversation

nolanderc
Copy link
Contributor

Motivation

Fixes #1700

Solution

Previously, inserting a new item into a DelayQueue after a value expired would result in all items in the queue to be postponed until the inserted item was ready. This was due to a delay keeping track of when the next item expires wasn't being updated correctly when a value was extracted from the wheel.

This PR makes sure that when a item expires, the DelayQueue updates the delay until the next item expires accordingly.

When the queue was polled and yielded an index from the wheel, the delay
until the next item was never updated. As a result, when one item was
yielded from `poll_idx` the following insert erronously updated the
delay to the instant of the inserted item.

Fixes: tokio-rs#1700
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 for getting this fix in! Test works well. I think the fix in poll_idx can be done a little differently, but overall looks good.

tokio/src/time/delay_queue.rs Outdated Show resolved Hide resolved
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!

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