Skip to content

alternative timer compatibility hazard #8198

@vilgotf

Description

@vilgotf

Version
1.49.0 and above (since the alternative timer was added)

Platform
N/A

Description
The alt timer does not retain the previous waker in Sleep::reset. When sharing Sleep and DelayQueue between tasks (e.g. Arc<Mutex<Pin<Box<Sleep>>>>), a task may lose its waker if another task calls reset. Waker retention was added in #2217 and #2290 (back in 0.2).

Rather than fixing the alternative timer, I would rather remove these spurious wakes and label cross-task sharing unsupported. This would be a minor compatibility break, as I doubt anyone actually uses this functionality (and whether we even knew about it). Alternatively, this should at least be internally documented, and perhaps publicly as well.

With this removed from Sleep, we would no longer need to store Option<Waker> in DelayQueue. That waker is only necessary to wake the task currently calling poll_expired after insert/remove operations (allowing it to reschedule itself).

Discovered in #8137, when I tried to normalize both implementations. This was not caught by our tests, as the alternative timer requires the multi-threaded runtime but our tests run on the current-threaded runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-bugCategory: This is a bug.M-timeModule: tokio/time

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions