Open
Description
Bevy version
0.16.1
What you did
#[derive(Component)]
struct A;
loop {
let w = World::new();
std::thread::scope(|s| {
let c1 = s.spawn(|| w.components_queue().queue_register_component::<A>());
let c2 = s.spawn(|| w.components_queue().queue_register_component::<A>());
let (c1, c2) = (c1.join().unwrap(), c2.join().unwrap());
assert_eq!(c1, c2);
});
}
What went wrong
After some iterations the assert_eq
fails.
Additional information
The issue is a TOCTOU bug in queue_register_component
: it first acquires and releases a read
lock to check if the component is registered, then forces a registration of the component if it wasn't already registered. However this ignored the possibility of another thread registering the component inbetween the check and the new registration.