Commit b93c72a
authored
Fix test failures caused by slow SIGCHLD handling (#922)
When I run the ksh test case, I occasionally encounter the error
sigchld.sh[77]: FAIL: SIGCHLD trap queueing failed -- expected
'running=0 maxrunning=4', got 'running=1 maxrunning=4'
as described in:
#344 (comment)
I tried to simplify the reproduction process
#!/bin/ksh
integer count=1
while true
do
jobmax=4
got=$(ksh -c '
JOBMAX='$jobmax' JOBCOUNT=$(('$jobmax'*2))
integer running=0 maxrunning=0
trap "((running--))" CHLD
for ((i=0; i<JOBCOUNT; i++))
do sleep 1 &
if ((++running > maxrunning))
then ((maxrunning=running))
fi
done
wait
sleep 1
print running=$running maxrunning=$maxrunning
')
exp='running=0 maxrunning='$jobmax
echo "when $count, expected '$exp', got '$got'"
((count++))
[[ $got == $exp ]] || exit 1
done
Without adding 'sleep', the script encounters the same error after
looping a few hundred times. With 'sleep' added, I have run it tens
of thousands of times in my local environment without seeing the
error.
The completion of 'wait' does not necessarily mean that the trap
has finished handling the SIGCHLD signal. Therefore, this error is
not a design flaw in ksh itself, but rather an issue with the test
case design. Adding an appropriate delay can prevent the test case
from failing due to this error.
src/cmd/ksh93/tests/sigchld.sh:
- The delay logic was modified to wait 0.1 seconds each time and
check whether running is 0, with a maximum total delay of 1
second.
At least in my local environment, a 1‑second delay is sufficient
to ensure that this test case passes.1 parent f314d14 commit b93c72a
2 files changed
+9
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
74 | 81 | | |
75 | 82 | | |
76 | 83 | | |
| |||
0 commit comments