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

Timeout: Unexpected build status after interrupting shell script

    Details

    • Similar Issues:

      Description

      When a timeout interrupts a shell script (bash in my case), the build result is set to failure instead of the expected aborted.

      Example (also true for scripted pipelines):

      pipeline {
          agent any
      
          options {
              timeout(time: 3, unit: 'SECONDS')
          }
      
          stages{
              stage('run') {
                  steps {
                      sh 'sleep 5'
                      // working:
                      // sleep(time: 5, unit: 'SECONDS')
                  }
              }
          }
      }
      

      Output:

      Started by user admin
      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] node
      Running on Jenkins in /mnt/data/jenkins-weekly/jenkins_home/workspace/timeout-pipeline
      [Pipeline] {
      [Pipeline] timeout
      Timeout set to expire in 3 sec
      [Pipeline] {
      [Pipeline] stage
      [Pipeline] { (run)
      [Pipeline] sh
      [timeout-pipeline] Running shell script
      + sleep 5
      Cancelling nested steps due to timeout
      Sending interrupt signal to process
      sh: line 1: 32445 Terminated              JENKINS_SERVER_COOKIE=$jsc '/mnt/data/jenkins-weekly/jenkins_home/workspace/timeout-pipeline@tmp/durable-7559496c/script.sh' > '/mnt/data/jenkins-weekly/jenkins_home/workspace/timeout-pipeline@tmp/durable-7559496c/jenkins-log.txt' 2>&1
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // timeout
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code 143
      Finished: FAILURE
      

        Attachments

          Activity

          Hide
          abayer Andrew Bayer added a comment -

          Are you only seeing this with shell steps, and not other steps (like, say, sleep)?

          Show
          abayer Andrew Bayer added a comment - Are you only seeing this with shell steps, and not other steps (like, say, sleep )?
          Hide
          abayer Andrew Bayer added a comment -

          Just verified that this is the case with sh but not with sleep, so it's probably something in workflow-durable-task...

          Show
          abayer Andrew Bayer added a comment - Just verified that this is the case with sh but not with sleep , so it's probably something in workflow-durable-task ...
          Hide
          abayer Andrew Bayer added a comment -

          So it looks like DurableTaskStep.Execution#check() is still getting called after DurableTaskStep.Execution#stop(Throwable) has been called, so the durable task/shell step is being killed before the timeout gets to actually kill it...

          Show
          abayer Andrew Bayer added a comment - So it looks like DurableTaskStep.Execution#check() is still getting called after DurableTaskStep.Execution#stop(Throwable) has been called, so the durable task/shell step is being killed before the timeout gets to actually kill it...
          Hide
          roel0 roel postelmans added a comment -

          This is really annoying, there is no option to check whetever the job time out or not

           

           

          Show
          roel0 roel postelmans added a comment - This is really annoying, there is no option to check whetever the job time out or not    
          Hide
          nodagoscha Stefan Angerer added a comment -

          To add note some more dangerous behaviour:

          steps {
            writeFile file: 'test.ps1', text: 'start-sleep 100'   
            timeout(time: 10, unit: 'SECONDS') {
                bat "@Powershell -Noninteractive -File \"${WORKSPACE}\\test.ps1\"" 
            }
          }
          

          This run on an windows agent will lead sometimes to success

          Show
          nodagoscha Stefan Angerer added a comment - To add note some more dangerous behaviour: steps {  writeFile file: 'test.ps1' , text: 'start-sleep 100'     timeout(time: 10, unit: 'SECONDS' ) {   bat "@Powershell -Noninteractive -File \" ${WORKSPACE}\\test.ps1\"" } } This run on an windows agent will lead sometimes to success

            People

            • Assignee:
              Unassigned
              Reporter:
              kgerstl Franz Kaefer
            • Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: