Skip to content

fix(native_surface): the Linux dmabuf importer stops and joins its read thread before releasing the device - #1620

Merged
Hona merged 1 commit into
devfrom
fix/noticed-linux-dmabuf-reader-join
Nov 23, 2026
Merged

Hona merged 1 commit into
devfrom
fix/noticed-linux-dmabuf-reader-join

Conversation

@Hona

@Hona Hona commented Nov 23, 2026

Copy link
Copy Markdown
Member

What was wrong

native_surface/linux.rs: Importer::new spawned a detached rune-dmabuf-read thread that owned a clone of the wgpu::Device and blocked in Device::poll(Wait { .. }) (up to 10 s) for each dmabuf copy. Nothing stopped or joined it: the thread exited only when the channel's Sender dropped, and SurfaceRenderer dropped its dmabuf importer last, after its own device. So a poll in flight, or one still queued, could run while the device and Vulkan driver were torn down. #1500 fixed the same race for the video completion thread.

What changed

  • pipeline/completion.rs: a new ReadWorker<T> runs queued items in order on a named thread. Its stop refuses new items, discards queued ones, and joins the thread. Like CompletionWorker, it handles caller unwinding, a callback panic, a lost device (the worker exits) and a drop from its own thread (it does not join itself). ReadWorker::spawn_device is the dmabuf wait. This code compiles on every platform, so its tests run on Windows.
  • linux.rs: Importer holds a ReadWorker declared before device, and Drop stops it. When the worker has stopped, on_read gets an error instead of being dropped without a call.
  • pipeline.rs: SurfaceRenderer declares dmabuf before device and stops the importer in Drop, after the completion worker.

Verification

  • 9 new read_worker_* tests in completion_tests.rs cover these cases: idle drop, drop during an in-flight wait (it blocks, then discards queued items), lost device, callback panic, caller unwind, self-drop, idempotent stop, and a real headless wgpu wait that runs on_read on rune-dmabuf-read and joins before drop returns. If stop does not join, read_worker_drop_waits_for_in_flight_wait_and_skips_queued_items and read_worker_device_notifies_on_read_and_drop_joins_in_flight_callback fail.
  • cargo test -p rune-media native_surface: 41 passed. read_worker tests passed in 5 repeated runs.
  • cargo check -p rune -p rune-kit passes, and so does scripts/file-size.sh.
  • cargo check -p rune-media --tests passes for Linux aarch64 in a container.

Not checked: a real dmabuf import on a Linux Vulkan GPU. The Linux code was only compiled, not run.

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.

1 participant