mirror of https://github.com/MingweiSamuel/Riven
fix: potential race condition in `Notified` `Drop` impl
parent
053622efc5
commit
0d0fa4f2dc
|
@ -6,6 +6,8 @@ use futures::future::FusedFuture;
|
||||||
use futures::FutureExt;
|
use futures::FutureExt;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
#[cfg(feature = "tracing")]
|
||||||
|
use tracing as log;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Notify {
|
pub struct Notify {
|
||||||
|
@ -64,10 +66,10 @@ impl Notify {
|
||||||
// Ensure generation matches before removing, to prevent ABA problem.
|
// Ensure generation matches before removing, to prevent ABA problem.
|
||||||
// If no match, means `Notify::notify_waiters` has already been called and deallocated us.
|
// If no match, means `Notify::notify_waiters` has already been called and deallocated us.
|
||||||
if internal.generation == generation {
|
if internal.generation == generation {
|
||||||
internal
|
if internal.waiters.try_remove(key).is_none() {
|
||||||
.waiters
|
// Rare race condition to get here, maybe?
|
||||||
.try_remove(key)
|
log::trace!("Tried to de-register `Notified` on drop but corresponding waker not found.");
|
||||||
.expect("Expected to drop registered `Notified` but waker not found.");
|
}
|
||||||
internal.waiters.shrink_to_fit();
|
internal.waiters.shrink_to_fit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue