Skip to content

Commit b93c72a

Browse files
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

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

COPYRIGHT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ksh 93u+m general copyright notice
2727
# Harald van Dijk <harald@gigawatt.nl> #
2828
# dnewhall <dnewhall@users.noreply.github.com> #
2929
# Chase <nicetrynsa@protonmail.ch> #
30+
# YoruStar <524413304@qq.com> #
3031
# Trey Valenta <t@trey.net> #
3132
# Sterling Jensen <5555776+sterlingjensen@users.noreply.github.com> #
3233
# SHIMIZU Akifumi <shimizu.akifumi@fujitsu.com> #

src/cmd/ksh93/tests/sigchld.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# #
33
# This software is part of the ast package #
44
# Copyright (c) 1982-2012 AT&T Intellectual Property #
5-
# Copyright (c) 2020-2024 Contributors to ksh 93u+m #
5+
# Copyright (c) 2020-2026 Contributors to ksh 93u+m #
66
# and is licensed under the #
77
# Eclipse Public License, Version 2.0 #
88
# #
@@ -13,6 +13,7 @@
1313
# David Korn <dgk@research.att.com> #
1414
# Martijn Dekker <martijn@inlv.org> #
1515
# Johnothan King <johnothanking@protonmail.com> #
16+
# YoruStar <524413304@qq.com> #
1617
# #
1718
########################################################################
1819

@@ -71,6 +72,12 @@ then
7172
fi
7273
done
7374
wait
75+
integer tries=0, maxtries=10
76+
while ((running > 0 && tries < maxtries))
77+
do
78+
sleep 0.1
79+
((tries++))
80+
done
7481
print running=$running maxrunning=$maxrunning
7582
')
7683
exp='running=0 maxrunning='$jobmax

0 commit comments

Comments
 (0)