Skip to content

test: Wait for the PipeWire loop thread before the teardown test stops it - #3593

Merged
vpacher merged 2 commits into
masterfrom
fix/3577-pipewire-teardown-start
Nov 3, 2026
Merged

vpacher merged 2 commits into
masterfrom
fix/3577-pipewire-teardown-start

Conversation

@vpacher

@vpacher vpacher commented Nov 3, 2026

Copy link
Copy Markdown
Member

What changed

test_pipewire_teardown_wait now creates its loop with thread-loop.start-signal and waits for that signal before it stops the loop. The test leaves the asan known list, and KNOWN_ENTRIES goes from 5 to 4.

New concept docs/knowledge/pipewire-stop-after-start.md.

Cause

This is a race in PipeWire (1.6.2, from reading its source):

  1. pw_thread_loop_stop() calls pw_loop_invoke(do_stop).
  2. loop_queue_invoke() reads impl->thread with no lock. If it is still 0, it treats the caller as the loop thread, so do_stop runs on the caller, with no wakeup.
  3. The loop thread enters the loop, sees running still true, and goes into epoll_wait.
  4. The caller sets running = false and waits in pthread_join. Nothing wakes the loop thread.

A stack of the hang shows the main thread in pthread_join under pw_thread_loop_stop, and the loop thread in epoll_wait. Attaching gdb ended the hang, because the interrupted epoll_wait lets the loop thread see the flag.

The loop thread sends the start signal after it has entered the loop, so a stop after that signal takes the normal path.

RED and GREEN

ASan build, 48 copies at a time, with 24 CPU hogs:

Test Runs Hangs
Before this PR 1632 2
Blocking pw_loop_invoke first (not this PR: it takes the same path) 3744 1
50 ms delay first (not this PR) 9600 0
This PR 43,200 0

On CI, the test hit the 10-minute limit in 2 of 13 asan jobs.

Test cost: no new test. The wait adds only the thread start.

Not in this PR

obs_pipewire_connect_fd() has the same race on its fail: path, when pw_context_connect_fd() fails right after the start. I did not reproduce that. A fix needs care, because the wait does not return on a PipeWire version that does not have this option.

Fixes #3577

🤖 Generated with Claude Code

vpacher and others added 2 commits November 3, 2026 23:09
…s it

pw_thread_loop_stop() can hang when it runs before the loop thread has
entered the loop. Invoke then runs do_stop on the caller, and nothing wakes
the loop thread if it is on its way into epoll_wait. Ask for PipeWire's start
signal and wait for it, and drop the test from the asan known list.

Fixes #3577

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #3577

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=6ca91016186f4c28dc34f928fccab976cb6495dc secs=269 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793744255,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9b162236985d802117c4a38aace7c47f603fc690a73eba7d37e66f3288133eff","lane":"lint","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":34,"stamp":"12aba21771c2fbd75546c20dde84cfd4","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9b162236985d802117c4a38aace7c47f603fc690a73eba7d37e66f3288133eff","lane":"lint","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":34,"stamp":"3b525dbe90040e1b5f290e9264a2d642","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8c5a69b63160fdd6c82bf71a44ebd412abded44b7969eedf65c3ff3ad442b916","lane":"rust-test","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":83,"stamp":"ce807bda133d5d0620388f20cb9457a4","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"1e7d3c70550159cfc3d53587e55902336ec073a2402c81969389c9f4da5f4414","lane":"cross","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":24,"stamp":"e600f320406f97a2e3b23aa68f1e6cb6","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"1e7d3c70550159cfc3d53587e55902336ec073a2402c81969389c9f4da5f4414","lane":"cross","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":24,"stamp":"15d39231417456c9a2afe84ce64d5b31","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"1e7d3c70550159cfc3d53587e55902336ec073a2402c81969389c9f4da5f4414","lane":"cross","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":24,"stamp":"c6ee3eef6d2f35a453cbb99a65eeaf46","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"1e7d3c70550159cfc3d53587e55902336ec073a2402c81969389c9f4da5f4414","lane":"cross","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":24,"stamp":"36750d4ef4da7df1d7cbb31ac85738e0","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
Ci-Attestation: {"at":1793744255,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"e505db2a69ec37c4c49b3649d0b5c77e58d4aea9aeb01653d69d98628212be15","lane":"tier2-linux","parents":["54b197cee0f2c691517e267558098a28844a98de"],"secs":269,"stamp":"197e1affded4d06cde3693392b0c6de5","tree":"6ca91016186f4c28dc34f928fccab976cb6495dc","v":1,"via":"run"}
@vpacher
vpacher requested a review from zackees as a code owner November 3, 2026 22:18
@vpacher
vpacher enabled auto-merge November 3, 2026 22:18
@vpacher
vpacher added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit f2ae924 Nov 3, 2026
37 checks passed
@vpacher
vpacher deleted the fix/3577-pipewire-teardown-start branch November 3, 2026 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: test_pipewire_teardown_wait hung for 10 minutes in the asan job

1 participant