test: use async-signal-safe exit in fork test panic hook - #200
Merged
2 commits merged intoJul 15, 2026
Merged
Conversation
std::process::exit flushes stdio and runs atexit handlers, which acquire locks. In a forked child of the multi-threaded test harness, a parallel test thread may hold the stderr mutex at fork time, leaving it permanently locked in the child. eprintln! and std::process::exit then deadlock, causing test_fork_agent_with_timeout to hang indefinitely. Replace with libc::write(2, ...) and libc::_exit, which are async-signal-safe and bypass all stdio/atexit locks. Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com> Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
libc::_exit skips atexit handlers, which is where the LLVM profile runtime writes .profraw files. The forked children that panic in the kata_agent tests exited without recording coverage, dropping kata_agent.rs below the 90% per-file gate. Under cfg(coverage) call __llvm_profile_write_file() explicitly before _exit. The profraw pattern contains %p, so each child writes its own file without clobbering the parent's. Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com> Assisted-By: Claude Fable 5 <noreply@anthropic.com>
zvonkok
force-pushed
the
fix/fork-safe-test-panic-hook
branch
from
July 15, 2026 22:57
2ea6190 to
5aeb7a4
Compare
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.
set_test_panic_hook()calledeprintln!andstd::process::exit(1).Both acquire stdio locks. In a multi-threaded test harness a parallel test
thread can hold the stderr mutex at the moment
fork()is called; that mutexappears locked-by-a-dead-thread in the child and can never be released.
The result is
test_fork_agent_with_timeouthanging indefinitely, whichblocked the
Static checks / cargo testjob on PR #186 for 6 hours untilthe runner cancelled it.
Replace with
libc::write(2, ...)andlibc::_exit(1), which areasync-signal-safe and bypass all stdio/atexit locking.