Repository navigation
fix(native_surface): SurfaceRenderer stops and joins its video completion thread before releasing the device - #1500
Merged
Merged
Conversation
…tion thread before releasing the device
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #767
Root cause
SurfaceRenderer(crates/rune-media/src/native_surface/pipeline.rs) spawned therune-video-completionthread holding a clonedwgpu::Deviceand discarded itsJoinHandle.Dropimpl,SurfaceRendererdroppeddevicebefore its completion channel sender and never joined the worker, letting an in-flightDevice::pollrace device and driver teardown (segfaulting at exit on Vulkan/NVIDIA).SurfaceRenderer::submit(crates/rune-media/src/native_surface/pipeline/frame.rs) also cloned the strongSyncSenderintoencoder.on_submitted_work_done, so channel-disconnect shutdown alone could block if a pending callback still held a sender.Changes
CompletionWorker(crates/rune-media/src/native_surface/pipeline/completion.rs) with an explicitSignalstate machine (Idle,Pending,Polling { rewake },Stopped) over aMutex + Condvarand an ownedJoinHandle.Drop for SurfaceRendererto releasetiming_queue(preventing an in-flight completion callback from submitting follow-up timestamp resolves) and callcompletion.stop(), which marksStopped, wakes the worker immediately out of idle or its 1 ms poll wait, and joins the thread beforeSurfaceRenderer.devicedrops.CompletionWakeclones never keep the worker alive).Err(_)exits and releases itswgpu::Deviceimmediately).StoppedviaExitGuardand drops its device; caller unwind joins without panicking inDrop).Stoppedwithout self-joining).crates/rune-media/src/native_surface/completion_tests.rscovering every worker exit path plus realSurfaceRendererdrop-joins-poll tests (with and without timestamp queries).stateDiagram-v2 [*] --> Idle Idle --> Pending: wake() Pending --> Polling: worker takes wakeup Polling --> Polling: wake() sets rewake=true Polling --> Idle: QueueEmpty & !rewake Idle --> Stopped: stop() Pending --> Stopped: stop() Polling --> Stopped: stop() / poll Err / unwind Stopped --> [*]Verification
cargo test -p rune-media dropping_surface_renderer_: failed ondevbefore the fix (SurfaceRenderer::dropreturned while the worker was still insidepoll), passed after the fix.cargo test -p rune-media native_surface: 27 passed (including 11 new tests innative_surface::completion_testsandcompletion_worker_preserves_cpu_gpu_overlap).cargo check -p rune -p rune-kit: passed.cargo check -p rune-media --no-default-features --target wasm32-unknown-unknown: passed.scripts/file-size.sh: passed (0 errors).