If the first command of a for or while loop is forked the following sleep seems to be forked or maybe even skipped too. Example broken: for i in 1 2 3 4 5 6 7 8 9; do echo test & sleep 5; done; echo test2 The former command does just take a few milliseconds. Compared to for i in 1 2 3 4 5 6 7 8 9; do echo test & /bin/sleep 5; done; echo test2 which takes quite some time. This issue was not existing in 1.35. Tested in an Alpine Linux Docker container. Thanks for your time!
This is because of built-in sleep [1] introduced in BusyBox 1.36.0 which exits when receiving SIGCHLD. Here is another way how to reproduce: /bin/sleep 1 & sleep 10 The purpose of the first command it to trigger SIGCHLD after one second. The second command should sleep for 10 seconds. - If running it in busybox, the command sequence exits after 1 second - If running it in bash, the command sequence exits after 10 second Similar problem was previously reported for "read" [2] and fix [3] was applied for it. -- Tero [1] https://git.busybox.net/busybox/commit/?id=58598eb7093561d914a6254697e137b815f1fdfc [2] https://www.mail-archive.com/busybox@busybox.net/msg24147.html [3] https://git.busybox.net/busybox/commit/?id=f5470419404d643070db99d058405b714695b817
Having a second look, I think it was this fix [1] that causes the problem as a side effect. It was released in 1.36.1. [1] https://git.busybox.net/busybox/commit/?h=1_36_1&id=ce839dea92ce10627094096835e831bf5d267631
*** Bug 15631 has been marked as a duplicate of this bug. ***
I marked bug 15631 as a duplicate of this bug. Before this bug is fixed, we can add a pair of parenthesis as a workaround. The "bug.sh" below demonstrates that "sleep 10" doesn't sleep, while the "fix.sh" shows the workaround pi:~# ./bug.sh Sun Jul 9 12:05:09 UTC 2023 Sun Jul 9 12:05:09 UTC 2023 pi:~# ./fix.sh Sun Jul 9 12:05:12 UTC 2023 Sun Jul 9 12:05:22 UTC 2023 pi:~# cat bug.sh date & sleep 10 date pi:~# cat fix.sh ( date & ) sleep 10 date
I'm disabling sleep builtin in ash, with a comment describing problems.