Skip to content

Remove deadlock potential from UncapturedErrorHandler. #8011

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

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

kpreid
Copy link
Collaborator

@kpreid kpreid commented Jul 26, 2025

Connections
Fixes #5395.

Description
Previously, the Device::on_uncaptured_error() callback was called with a device-wide mutex held. This provides synchronization we don’t actually promise to the user and which the user cannot take advantage of (because the callback signature is not FnMut), and allows a deadlock to occur via reentrancy.

Instead,

  • Call the callback without the mutex held.
  • To enable this, accept it wrapped in Arc instead of Box, and require it to be Send + Sync rather than just Send.

An alternative to the approach in this PR would be to explicitly document that the callback is called with a mutex held. In that case, the callback should be made FnMut to allow it to take advantage of this — the opposite of this PR's change to Fn + Sync.

Testing
Added a test case for the now-impossible deadlock.

Squash or Rebase?
Rebase.

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@kpreid kpreid requested a review from a team as a code owner July 26, 2025 16:52
It makes sense for a function to be `FnMut + Send`, or `Fn + Send + Sync`,
but not `Fn + Send` because that is overly restrictive for the caller and
the callee.
@kpreid kpreid added the area: api Issues related to API surface label Jul 26, 2025
This will be necessary for the next change.
This prevents a possible deadlock if the callback itself calls wgpu
operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: api Issues related to API surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bound of UncapturedErrorHandler is more restrictive than it should be
1 participant