Repository navigation
[deno] Don't panic on a lost device, and resolve device.lost after destroy() - #10
matthargett wants to merge 2 commits into
Conversation
Three places in deno_webgpu aborted the process when the driver lost the device: - `mapAsync()` and `onSubmittedWorkDone()` wait with `poll(wait_indefinitely()).unwrap()`. A lost device makes the poll fail. Reject the mapping with an `AbortError`, and resolve `onSubmittedWorkDone()`. - Their completion callbacks `unwrap()` a channel send whose receiver is gone once the wait has failed. - The task that resolves `device.lost` and the finalizer of the JS device object both remove the lost-promise resolver, and the task `unwrap()`s it. If the object is collected between the loss and the task, the task panics (`adapter.rs`, "called `Option::unwrap()` on a `None` value"). The per-device tables were also keyed by the address of the wgpu device, so a stale task or finalizer for a freed device could act on a newer device at the same address. Key them by a counter instead.
`GPUDevice.destroy()` polled the device once without blocking. wgpu calls the device-lost closure only once the device's submissions have completed, so if one was still in flight the closure was not called, nothing polls a destroyed device again, and `device.lost` never resolved. The WebGPU CTS awaits `device.lost` when it tears a test's device down. For a test that had just called `queue.submit()`, such as `api,operation,uncapturederror:iff_uncaptured`, the event loop ran out of work with that promise pending, and `cts_runner` exited with status 0 without printing a result for any case, which `cargo xtask cts` counts as a pass. Wait for the device's work to finish in `destroy()`.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d65760398
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .is_err() | ||
| { | ||
| return Ok(()); |
There was a problem hiding this comment.
Complete the entire queue wait when polling fails
If the device is lost while submissions are outstanding, returning Ok(()) only completes device_poll_fut; the tokio::try_join! below still waits for receiver_fut. In wgpu-core/src/device/resource.rs, a HAL wait or fence-query error returns from Device::maintain before queue maintenance collects submission callbacks, and Device::lose does not invoke those callbacks either. Consequently, the sender can remain stored in the queue while this method stops polling, leaving onSubmittedWorkDone() pending indefinitely. Make the poll-error path complete the overall operation without continuing to await the callback.
Useful? React with 👍 / 👎.
Connections
Found running the WebGPU CTS with
cts_runneron a Mali-G52 MC2 whose driver loses the device in several tests (#7, #8 and #9 are the driver-side fixes). Nothing here is specific to that device; the second commit changes whatcts_runnerreports on macOS too.Description
destroy()anddevice.lost.GPUDevice.destroy()polls once without blocking. wgpu only calls the device-lost closure once submissions have completed, so with one in flightdevice.lostnever resolves. The CTS awaits it at teardown; the event loop then runs dry andcts_runnerexits with status 0 without results for the remaining cases, whichcargo xtask ctscounts as a pass.destroy()now waits for the device's work to finish.Panics on a lost device.
mapAsync()andonSubmittedWorkDone()unwrap()a poll that fails once the device is lost, as do their completion callbacks' channel sends. The task that resolvesdevice.lostunwrap()s a resolver the JS object's finalizer may already have removed.mapAsync()now rejects with anAbortError,onSubmittedWorkDone()resolves, and the rest return quietly. The per-device tables are keyed by a counter instead of the device's address, which could be reused.Testing
cargo fmt --checkand clippy for deno_webgpu and cts_runner are clean;cargo test -p cts_runnerpasses.cts_runnerbuilt from trunk60cef2be8and from this branch:mapAsync():uncapturederror:iff_uncapturedanderror_scopeon the Mali-G52, 53 cases: on trunk 26 report a result (two processes exit with status 0 early); all 53 pass with this branch.cts_runner/test.lston the device (54,915 of 54,931 cases; 16 left out to protect the phone's memory): 45,478 pass, 86 fail, 9,351 skip. 85 of the failures are in selectors markedfails-if(vulkan).Squash or Rebase?
Rebase. The two commits are independent.
LLM Use?
Claude Code (Claude Mythos 5.2) found these on the device, traced the silent exit to
destroy(), wrote the code, ran the tests and drafted this description.