Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55867

sh step termination is never detected if the wrapper process is killed

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Component/s: durable-task-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.150.2
      Durable Task Plugin 1.28
    • Similar Issues:

      Description

      When you execute a shell step, Jenkins runs a wrapper shell process that's responsible for saving the exit code of your script. If this process is killed, then Jenkins never discovers that your script has terminated, and the step hangs forever.

      This can be easily demonstrated by killing the wrapper process yourself:

       node() {
            sh 'kill $PPID'
       }
      

      Run this pipeline and the sh step will never terminate.

      I believe this happens due to a bug in the log-touching subshell spawned by the wrapper process. Specifically, the subshell checks whether the wrapper process is still alive with this expression:

       \( -d /proc/$pid -o \! -d /proc/$$ \)
      

      But $$ expands to the PID of the parent shell, not the subshell. This means that $pid and $$ are the same thing, and the whole expression always evaluates to true.

        Attachments

          Issue Links

            Activity

            Hide
            danielzabel Daniel Zabel added a comment -

            example code to visualize the issue:

             

            pid=$$; { echo "$pid - $$"; }

            outputs:

            11953 - 11953
            
            Show
            danielzabel Daniel Zabel added a comment - example code to visualize the issue:   pid=$$; { echo "$pid - $$" ; } outputs: 11953 - 11953
            Hide
            danielzabel Daniel Zabel added a comment -

            seems to be the root cause for

            Show
            danielzabel Daniel Zabel added a comment - seems to be the root cause for
            Hide
            danielzabel Daniel Zabel added a comment -

            I guess what you want should something lokk like this:

            pid=$$; ( echo "$pid - $PPID"; )
            

            outputs:

            19499 - 11953
            

            where 19499 is the pid of the started sh and 11953 is the pid of the parent process (in this case the wrapper i guess)

            Show
            danielzabel Daniel Zabel added a comment - I guess what you want should something lokk like this: pid=$$; ( echo "$pid - $PPID" ; ) outputs: 19499 - 11953 where 19499 is the pid of the started sh and 11953 is the pid of the parent process (in this case the wrapper i guess)

              People

              • Assignee:
                stevenfoster Steven Foster
                Reporter:
                rdonchen_intel Roman Donchenko
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: