@@ -189,13 +189,20 @@ extension SubprocessUnixTests {
189189 arguments: [
190190 " -c " ,
191191 """
192- set -e
193- trap 'echo saw SIGQUIT;' QUIT
194- trap 'echo saw SIGTERM;' TERM
195- trap 'echo saw SIGINT; exit 42;' INT
192+ trap 'echo saw SIGQUIT' QUIT
193+ trap 'echo saw SIGTERM' TERM
194+ trap 'echo saw SIGINT; exit 42' INT
196195 echo ready
197- while true; do sleep 0.1; done
198- exit 2
196+ # A trapped signal interrupts `wait` immediately, so the handler runs
197+ # without waiting for a sleep interval to elapse, unlike a foreground
198+ # `sleep`, whose completion (and the trap deferred behind it) can slip
199+ # past the teardown window under load. The backgrounded sleep is short
200+ # so a signal landing as bash enters the wait is still serviced within
201+ # one interval rather than stranding on a long-lived child.
202+ while true; do
203+ sleep 0.2 &
204+ wait $!
205+ done
199206 """ ,
200207 ] ,
201208 input: . none,
@@ -205,8 +212,8 @@ extension SubprocessUnixTests {
205212 return try await withThrowingTaskGroup ( of: Void . self) { group in
206213 // Gate the teardown task on bash having actually installed
207214 // its signal traps. The reader signals readiness when it
208- // sees the `ready` marker the script prints after the
209- // `trap` lines .
215+ // sees the `ready` marker the script prints once its traps are
216+ // installed, just before it begins waiting .
210217 let ( readyStream, readyContinuation) = AsyncStream . makeStream ( of: Void . self)
211218
212219 group. addTask {
0 commit comments