-
Notifications
You must be signed in to change notification settings - Fork 937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v0.19] Fix Buffer Mapping Deadlock #5517
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh gawd. this is insanely evil
you're missing a changelog note though, imho worth pointing out that there's a fix (we should give people reasons to update ;-))
changelog got promised to be done upon the release processing :) |
// This _cannot_ be inlined into the match. If it is, the lock will be held | ||
// open through the whole match, resulting in a deadlock when we try to re-lock | ||
// the buffer back to active. | ||
let mapping = std::mem::replace( | ||
&mut *buffer.map_state.lock(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should ReentrantMutex used to prevent double locking causing deadlock?
A mutex which can be recursively locked by a single thread.
This type is identical to Mutex except for the following points:
- Locking multiple times from the same thread will work correctly instead of deadlocking.
- ReentrantMutexGuard does not give mutable references to the locked data. Use a RefCell if you need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No - there is a cost to reentrant mutexes and none of our mutexes require reentrency.
We have a PR open which adds a debug check to make sure we don't lock locks in a way that could cause a deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this while using wgpu-profiler.
Subtle temporary extension caused a deadlock in buffer mapping code.