Skip to content

test: use async-signal-safe exit in fork test panic hook - #200

Merged
2 commits merged into
NVIDIA:mainfrom
zvonkok:fix/fork-safe-test-panic-hook
Jul 15, 2026
Merged

test: use async-signal-safe exit in fork test panic hook#200
2 commits merged into
NVIDIA:mainfrom
zvonkok:fix/fork-safe-test-panic-hook

Conversation

@zvonkok

@zvonkok zvonkok commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

set_test_panic_hook() called eprintln! and std::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 mutex
appears locked-by-a-dead-thread in the child and can never be released.
The result is test_fork_agent_with_timeout hanging indefinitely, which
blocked the Static checks / cargo test job on PR #186 for 6 hours until
the runner cancelled it.

Replace with libc::write(2, ...) and libc::_exit(1), which are
async-signal-safe and bypass all stdio/atexit locking.

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>
Copilot AI review requested due to automatic review settings July 15, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 15, 2026 22:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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>
Copilot AI review requested due to automatic review settings July 15, 2026 22:57
@zvonkok
zvonkok force-pushed the fix/fork-safe-test-panic-hook branch from 2ea6190 to 5aeb7a4 Compare July 15, 2026 22:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zvonkok zvonkok added the ok-to-test Ok to test label Jul 15, 2026
@zvonkok
zvonkok enabled auto-merge July 15, 2026 23:22
@zvonkok zvonkok closed this pull request by merging all changes into NVIDIA:main in 8139d4c Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Ok to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants