Make testTeardownSequence() resilient to scheduling latency#300
Merged
iCharlesHu merged 1 commit intoJun 9, 2026
Merged
Conversation
The test drove a `teardown(using:)` sequence (`SIGQUIT`, `SIGTERM`, then `SIGINT`, each with a grace period, ending in an implicit `SIGKILL`) against a bash child whose `INT` trap echoes and `exit 42`s, and which otherwise looped in a foreground `sleep 0.1`. On a loaded Linux runner it failed with `signaled(9)` and a transcript missing the final `saw SIGINT`. Bash defers a trapped signal until the running foreground command completes. When scheduling pressure delayed the deferred `INT` trap past the grace period, the implicit `SIGKILL` reached the child before its deferred `INT` trap ran, so it died on the signal instead of exiting `42`. Only the `SIGINT` step gates anything; the `QUIT` and `TERM` traps just echo, so those steps always run their full duration regardless of timing, which is why the sequence got that far and no further. Idle in `wait` on a backgrounded `sleep` instead. A trapped signal interrupts `wait` immediately and runs the handler at once, with no dependence on a sleep interval elapsing, so the `INT` trap fires well inside the grace period even under load. The backgrounded `sleep` is short so a signal that lands as bash enters the `wait` is serviced at the next safe point within one interval, rather than blocking on a long-lived child.
This was referenced Jun 6, 2026
jakepetroules
approved these changes
Jun 8, 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.
testTeardownSequence()failed on a CI run for an unrelated Windows-only change in #296:The test drove a
teardown(using:)sequence (SIGQUIT,SIGTERM, thenSIGINT, each with a grace period, ending in an implicitSIGKILL) against a bash child whoseINTtrap echoes andexit 42s, and which otherwise looped in a foregroundsleep 0.1. On a loaded Linux runner it failed withsignaled(9)and a transcript missing the finalsaw SIGINT.Bash defers a trapped signal until the running foreground command completes. When scheduling pressure delayed the deferred
INTtrap past the grace period, the implicitSIGKILLreached the child before its deferredINTtrap ran, so it died on the signal instead of exiting42. Only theSIGINTstep gates anything; theQUITandTERMtraps just echo, so those steps always run their full duration regardless of timing, which is why the sequence got that far and no further.This PR idles in
waiton a backgroundedsleepinstead. A trapped signal interruptswaitimmediately and runs the handler at once, with no dependence on a sleep interval elapsing, so theINTtrap fires well inside the grace period even under load. The backgroundedsleepis short, so a signal that lands as bash enters thewaitis serviced at the next safe point within one interval, rather than blocking on a long-lived child.I ran the pre-fix test on GitHub Actions under heavy CPU oversubscription on the same amazonlinux2 nightly image, but wasn't able to reproduce the failure across 500 iterations. The failure is load-dependent so it's possible I didn't recreate the exact scenario, or this reproduces too rarely to surface in 500 runs.