Fix buffer map/destroy race#9610
Conversation
3084e8a to
f1acfc0
Compare
f1acfc0 to
9a1e7b7
Compare
|
Thanks for this. We may not take the change right away, because there is some other locking cleanup (#9524 and #9479) that will put us on firmer ground for assessing locking correctness. But we definitely want to fix it at some point.
I mentioned in the issue that I have a stress test that is able to reproduce the problem. If I get a chance I will clean that up and see if we can include it in CI. The proposed unit test is just illustrating code behavior without exercising the implementation, so doesn't have a lot of value. Even if it did exercise the implementation, it can be hard to get good coverage of problems like this one with unit tests. |
|
Hiii , So I originally only focused on the specific But however after your comment I did a pass over the other I can remove the test if you want, or leave the PR until #9524 / #9479 land and the lock-validation picture is clearer. |
Fixes #9552.
Buffer::maptemporarily exposedBufferMapState::Idlewhile completing a pending map. During that window,buffer_destroycould callunmap, observeIdle, and continue destroying the buffer while the map path was still completing.keeps
map_statelocked across the temporaryWaiting -> Idle -> Activetransition, sounmap/buffer_destroycannot observe the transientIdlestate during map completion.Also added a focused state-machine regression test covering the core property: another thread cannot acquire
map_stateand observe the temporaryIdlevalue while the map path still holds the lock.Testing:
cargo fmt --checkcargo check -p wgpu-corecargo test -p wgpu-core temporary_idle_map_state_is_not_observable_without_lockcargo test -p wgpu-core