Closed MrGunflame closed 3 months ago
Waking a waker when returning Poll::Ready causes the task to be polled after being deallocated.
Poll::Ready
A future that triggers the problem:
fn foo() -> impl Future<Output = ()> { poll_fn(|cx| { cx.waker().wake_by_ref(); Poll::Ready(()) }) }
Waking the waker multiple times causes the task to be scheduled multiple times. This can cause multiple threads to start polling the same task at the same time. It also causes the same task to be deallocated multiple times.
fn foo() -> impl Future<Output = ()> { poll_fn(|cx| { cx.waker().wake_by_ref(); cx.waker().wake_by_ref(); Poll::Pending }) }
Waking a waker when returning
Poll::Ready
causes the task to be polled after being deallocated.A future that triggers the problem:
Waking the waker multiple times causes the task to be scheduled multiple times. This can cause multiple threads to start polling the same task at the same time. It also causes the same task to be deallocated multiple times.
A future that triggers the problem: