Configuration Information:
Machine: x86_64
OS: linux-gnu (Debian 13, WSL2 kernel 6.18)
Bash Version: 5.2.37(1)-release (Debian package); also 5.3.20(1)-release, built
from bash-5.3.tar.gz plus patches 001-020 with a plain ./configure

Description:
      With a trap on SIGTERM, a loop whose body runs `continue` sometimes never
      runs the trap: the signal is lost and the script keeps running. Sending
      SIGTERM to 40 copies of the script below, 1 second after they start, left
      9-17 of the 40 running after 3 seconds, on both versions, on an idle
      machine. The trap's first command (an append to a file) did not run in
      those copies, so the trap was never entered, not entered and then failing.
      The same loop with `:` in place of `continue` lost none in 80 tries; a
      `while read` loop whose body only runs `continue` lost 10 of 80.

Repeat-By:
      cat >forcont.sh <<'EOF'
      trap 'echo "$$" >>trapped; exit 143' TERM
      while :; do for ((i = 0; i < 20000; i++)); do continue; done; done
      EOF
      pids=()
      for i in $(seq 1 40); do bash forcont.sh & pids+=($!); done
      sleep 1; kill -TERM "${pids[@]}"; sleep 3
      alive=0
      for p in "${pids[@]}"; do kill -0 "$p" 2>/dev/null && alive=$((alive + 
1)); done
      echo "alive=$alive of 40"    # expected 0; we see 9-17
      kill -KILL "${pids[@]}" 2>/dev/null

Fix:
      Unknown. As a workaround we run the loop in a child process and have
      the parent, which only waits, receive the signal.


Cheers.


[cid:6cc5eeca-6aac-4e58-9c0f-4ad1acf0ce02]<https://www.skillonnet.com/>


Dimitrios Christou
DevOps
Email: [email protected]

SkillOnOps



Connect with us:

[cid:f5a294c6-ba31-44fa-ae8f-58a66372b1a6]<https://www.instagram.com/skillonnet/>
  [cid:52273179-e195-4a22-92d2-bbac003a0e55] 
<https://www.facebook.com/skillonnet/>   
[cid:9b0988a3-43d7-4d35-9dac-9640533893c1] 
<https://linkedin.com/company/skillonnet>
www.SkillOnNet.com<https://www.skillonnet.com/>



This email and the information it contains, including any attachments, is 
confidential and may be legally privileged. It is intended solely for the 
recipient(s) to whom it is addressed. If you are not the intended recipient you 
are notified that disclosing, copying, distributing, or taking any action in 
reliance on the contents of this information is strictly prohibited. If you 
have received this email in error, please immediately contact the sender and 
delete this email from your system. Any other action in relation to, or in 
reliance on this email is strictly prohibited, including unauthorized copying, 
printing, disclosure, or distribution of this email or any of its content, and 
you will be held responsible for any such action. Statements and opinions 
expressed in this email are those of the sender, and do not necessarily reflect 
those of “SkillOnNet Ltd”. SkillOnNet Ltd accepts no liability for damage 
caused by any malware transmitted by this email.Any personal data contained in 
this email will be processed in accordance with the company's Privacy Policy, 
which is available on our website

Reply via email to