[LTP] [PATCH] test_children_cleanup.sh: Fix race condition

Li Wang liwang@redhat.com
Tue Feb 15 05:30:35 CET 2022


On Tue, Feb 15, 2022 at 12:51 AM Martin Doucha <mdoucha@suse.cz> wrote:

> Processes can stay alive for a short while even after receiving SIGKILL.
> Give the child in subprocess cleanup libtest up to 5 seconds to fully exit
> before reporting that it was left behind.


> Signed-off-by: Martin Doucha <mdoucha@suse.cz>
> ---
>  lib/newlib_tests/test_children_cleanup.sh | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
>
> diff --git a/lib/newlib_tests/test_children_cleanup.sh
> b/lib/newlib_tests/test_children_cleanup.sh
> index 4b4e8b2f0..44505aa51 100755
> --- a/lib/newlib_tests/test_children_cleanup.sh
> +++ b/lib/newlib_tests/test_children_cleanup.sh
> @@ -10,10 +10,19 @@ rm "$TMPFILE"
>  if [ "x$CHILD_PID" = "x" ]; then
>         echo "TFAIL: Child process was not created"
>         exit 1
> -elif ! kill -s 0 $CHILD_PID &>/dev/null; then
> -       echo "TPASS: Child process was cleaned up"
> -       exit 0
> -else
> -       echo "TFAIL: Child process was left behind"
> -       exit 1
>  fi
> +
> +# The child process can stay alive for a short while even after receiving
> +# SIGKILL, especially if the system is under heavy load. Wait up to 5
> seconds
> +# for it to fully exit.
>


It doesn't work for all platforms and we can not guarantee how long it will
cost before PID 1 reaps zombie process.

Also, I just get to know that  Docker does not run processes under a
special init process that properly reaps child processes, so that it is
possible for the container to end up with zombie processes that cause
all sorts of trouble.

I even try adding `kill -SIGCHLD 1` but does not work as expected.

See CI jobs:
  https://github.com/wangli5665/ltp/runs/5194270998?check_suite_focus=true
<https://mail.google.com/mail/u/1/%E2%80%8Bhttps://github.com/wangli5665/ltp/runs/5194270998?check_suite_focus=true>

Therefore, I suggest giving a chance to my refined patch V2 :).

--- a/lib/newlib_tests/test_children_cleanup.sh
+++ b/lib/newlib_tests/test_children_cleanup.sh
@@ -10,10 +10,16 @@ rm "$TMPFILE"
 if [ "x$CHILD_PID" = "x" ]; then
        echo "TFAIL: Child process was not created"
        exit 1
+elif grep -q "Z (zombie)" /proc/$CHILD_PID/status; then
+       echo "TPASS: Child process is in zombie state"
+       exit 0
 elif ! kill -s 0 $CHILD_PID &>/dev/null; then
        echo "TPASS: Child process was cleaned up"
        exit 0
 else
        echo "TFAIL: Child process was left behind"
+       echo "cat /proc/$CHILD_PID/status"
+       echo "---------------------------"
+       cat /proc/$CHILD_PID/status
        exit 1
 fi


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220215/41db83c0/attachment-0001.htm>


More information about the ltp mailing list