Skip to content

Fixed a deadlock caused by locking the device's snatchable lock after locking the queue's pending writes #7582

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

Merged
merged 1 commit into from
Apr 21, 2025

Conversation

RedMindZ
Copy link
Contributor

Connections
May be connected to some of the open deadlock issues, but I haven't investigated them thoroughly.

Description
There is a deadlock in Queue::write_buffer and Queue::write_staging_buffer that is caused by taking the device's snatchable lock after locking the queue's pending writes. This violates the lock ranking, which states that the device's snatchable lock must be taken first. This is fixed by simply reversing the order in which the locking occurs.

Testing
I initially caught this deadlock by updating wgpu from v0.20 to to v25.0, and having my application deadlock afterwards.
After implementing the change, the application no longer deadlocks.

Squash or Rebase?
This is a single commit.

Checklist

  • Run cargo fmt.
  • Run cargo test.
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@RedMindZ RedMindZ requested a review from a team as a code owner April 20, 2025 21:22
@ErichDonGubler ErichDonGubler self-assigned this Apr 21, 2025
@ErichDonGubler
Copy link
Member

A great first contribution to WGPU. 🙂 Glad you could figure out the problem!

@ErichDonGubler ErichDonGubler merged commit f64eae7 into gfx-rs:trunk Apr 21, 2025
37 checks passed
@RedMindZ RedMindZ deleted the deadlock-fix branch April 21, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants