Repository navigation
Description
Symptom
A C program that links libmoq.a, consumes a video track, and then exits normally (returning from main, or calling exit) can abort during atexit teardown with glibc's priority-protected-mutex assertion in __pthread_tpp_change_priority. The process dies with SIGABRT (exit 134) and a core dump after the MoQ data path has already worked correctly.
This has only been observed on Linux/glibc.
Where it bit us
The C leg of the interop smoke test (test/smoke/clients/c/subscribe.c). 17bf0d9 worked around it by having the client _exit(0) the moment it has its frame, skipping atexit teardown entirely, with the commit message "Fixes the flaky rust -> c leg". The workaround was never accompanied by a diagnosis, so per CLAUDE.md's Root Cause First this should be treated as a real bug rather than a flake that's been made to go away.
#2675 extends the same _exit to the client's failure paths, for a separate reason (a use-after-free on user_data). It does not touch this.
Why this matters beyond the smoke test
The smoke client is not the only C consumer. cpp/obs links libmoq the same way, and the C API's whole contract is "call moq_session_close, wait for the terminal on_status, exit". A consumer that follows that contract exactly should not abort. Right now the only thing keeping our own test green is that it skips the C runtime's exit path, which is not advice we can reasonably give an embedder.
What is known
libmoq.astatically bundlesmoq-video, whose software H.264 fallback is openh264 (vendored C++;stdc++is inrs/libmoq/native-libs/linux.txtfor exactly that reason).- Nothing in our Rust code creates a priority-protected mutex.
grepforPTHREAD_PRIO/pthread_mutexattr/SCHED_acrossrs/moq-videoandrs/libmoqcomes back empty, so the mutex in question comes from a dependency or is not really a PRIO_PROTECT mutex at all (see below). - libmoq runs its own tokio runtime on a
LazyLockthread (rs/libmoq/src/state.rs), which is never shut down; its threads are still live when C's atexit handlers and static destructors run.
Hypotheses, none confirmed
- A
pthread_mutex_tis used after free during teardown.__pthread_tpp_change_priorityis only reached whenm->__data.__kindsays PRIO_PROTECT. If the mutex memory has already been freed, a garbage__kindcan route an ordinary unlock/destroy down the TPP path with a nonsense priority, which is precisely what that assertion catches. This would make the assertion a symptom of a lifetime bug, not of anything priority-related. - A race between the still-running tokio/openh264 worker threads and C's static destructors. We never stop the runtime, so a worker can touch state whose destructor already ran.
- Something in the static-link arrangement, e.g. openh264's C++ statics being destroyed while a thread is inside them.
Hypothesis 1 is the one worth checking first, because it is the only one that would also be a live bug for a well-behaved embedder rather than a teardown-ordering nuisance.
Suggested investigation
- Reproduce with a minimal C program: connect, consume video,
moq_session_close, wait for the terminalon_status,return 0. Loop it to get a hit rate. - Run it under ASan and under valgrind/helgrind. If hypothesis 1 is right, ASan should name the freed mutex directly.
- Get a backtrace from the core: whether the abort comes from
pthread_mutex_destroy,pthread_mutex_unlock, or a static destructor narrows this a lot. - Check whether it still reproduces with
moq-video's software H.264 fallback out of the link, which would implicate openh264 specifically.
Definition of done
A C consumer that returns from main after closing its session exits cleanly, and test/smoke/clients/c/subscribe.c no longer needs _exit to dodge teardown.
(written by Opus 5)
Activity
coderabbitai commentedon Aug 5, 2026
🔗 Related PRs
#1068 - Add comprehensive FFI integration tests for libmoq broadcast [closed]
#1782 - fix(ci): unbreak the self-hosted A1 runner (libmoq clippy + ffmpeg bindgen headers) [merged]
#1875 - fix: link macOS CoreServices for the bundled notify/FSEvents backend [merged]
#2025 - fix(smoke): _exit the C client so a racing frame callback can't corrupt the stack [merged]
#2669 - fix(libmoq): unbreak the Linux C link list, and make VAAPI opt-in [open]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
fix(smoke): drain the C client's registrations before main returns
fix(smoke): drain the C client's registrations before main returns