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

Pipeline retry operation doesn't retry when there is a timeout inside of it

      When a timeout call is fired inside of a retry, retry is not being triggered and job execution is aborted, the only way to make it work is by surrounding the timeout operation with a try/catch.

      without try/catch

      Log output

      Cancelling nested steps due to timeout
      

      Execution result

      Timeout has been exceeded
      Finished: ABORTED
      

      with try/catch

      Log output

      Timeout set to expire after 2 sec without activity
      Sleeping for 2 sec
      Cancelling nested steps due to timeout
      ERROR: catched timeout! org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
      Retrying
      

      Execution result

      Finished: SUCCESS
      

       

      Examples to reproduce the issue

      Failing example

      node {
          def timeoutSeconds = 3
          stage('Preparation') { // for display purposes
              retry(3){
                  timeout(activity: true, time: 2, unit: 'SECONDS') {
                      sleep(timeoutSeconds)
                  }
                  timeoutSeconds--
              }
         }
      }
      

      Working example

      node {
          def timeoutSeconds = 3
          stage('Preparation') { // for display purposes
              retry(3){
                  try{
                      timeout(activity: true, time: 2, unit: 'SECONDS') {
                          sleep(timeoutSeconds)
                      }
                  }catch(err){
                      timeoutSeconds--
                      script{
                        def user = err.getCauses()[0].getUser()
                        error "[${user}] catched timeout! $err"
                      }
                  }
              }
         }
      }
      

          [JENKINS-51454] Pipeline retry operation doesn't retry when there is a timeout inside of it

          David Constenla created issue -
          Sam Van Oort made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: groovy-plugin [ 15549 ]
          Component/s Original: pipeline [ 21692 ]
          Sam Van Oort made changes -
          Assignee Original: vjuranek [ vjuranek ] New: Amita Bhasin [ ab ]
          Sam Van Oort made changes -
          Assignee Original: Amita Bhasin [ ab ] New: Andrew Bayer [ abayer ]
          Andrew Bayer made changes -
          Labels Original: abort declarative pipeline retry timeout New: abort declarative pipeline retry timeout triaged-2018-11

          It looks like the org.jenkinsci.plugins.workflow.steps.FlowInterruptedException exception could be the  cause. If the timeout directive would throw another exception, would this solve the issue?

          Nepomuk Seiler added a comment - It looks like the org.jenkinsci.plugins.workflow.steps.FlowInterruptedException exception could be the  cause. If the timeout directive would throw another exception, would this solve the issue?

          If capturing the `FlowInterruptedException` it will retry also when aborting the job for any other reason, like canceling. Definitively, timeout should thow a different exception.

          Luis Piedra-Márquez added a comment - If capturing the ` FlowInterruptedException` it will retry also when aborting the job for any other reason, like canceling. Definitively, timeout should thow a different exception.

          Basil Crow added a comment -

          I can reproduce this error in a scripted pipeline as well.

          Basil Crow added a comment - I can reproduce this error in a scripted pipeline as well.
          Basil Crow made changes -
          Summary Original: Declarative pipeline retry operation doesn't retry when there is a timeout inside of it New: Pipeline retry operation doesn't retry when there is a timeout inside of it
          Basil Crow made changes -
          Description Original: When a declarative {{timeout}} call is fired inside of a {{retry}}, *retry is not being triggered* and *job execution is aborted*, the only way to make it work is by surrounding the {{timeout}} operation with a {{try/catch}}.

          h3. without try/catch
          Log output
          {code}
          Cancelling nested steps due to timeout
          {code}
          Execution result
          {code}
          Timeout has been exceeded
          Finished: ABORTED
          {code}

          h3. with try/catch
          Log output
          {code}
          Timeout set to expire after 2 sec without activity
          Sleeping for 2 sec
          Cancelling nested steps due to timeout
          ERROR: catched timeout! org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
          Retrying
          {code}
          Execution result
          {code}
          Finished: SUCCESS
          {code}
           
          h2. Examples to reproduce the issue
          h3. Failing example
          {code:java}
          node {
              def timeoutSeconds = 3
              stage('Preparation') { // for display purposes
                  retry(3){
                      timeout(activity: true, time: 2, unit: 'SECONDS') {
                          sleep(timeoutSeconds)
                      }
                      timeoutSeconds--
                  }
             }
          }
          {code}

          h3. Working example
          {code:java}
          node {
              def timeoutSeconds = 3
              stage('Preparation') { // for display purposes
                  retry(3){
                      try{
                          timeout(activity: true, time: 2, unit: 'SECONDS') {
                              sleep(timeoutSeconds)
                          }
                      }catch(err){
                          timeoutSeconds--
                          script{
                            def user = err.getCauses()[0].getUser()
                            error "[${user}] catched timeout! $err"
                          }
                      }
                  }
             }
          }
          {code}
          New: When a {{timeout}} call is fired inside of a {{retry}}, *retry is not being triggered* and *job execution is aborted*, the only way to make it work is by surrounding the {{timeout}} operation with a {{try/catch}}.

          h3. without try/catch
          Log output
          {code}
          Cancelling nested steps due to timeout
          {code}
          Execution result
          {code}
          Timeout has been exceeded
          Finished: ABORTED
          {code}

          h3. with try/catch
          Log output
          {code}
          Timeout set to expire after 2 sec without activity
          Sleeping for 2 sec
          Cancelling nested steps due to timeout
          ERROR: catched timeout! org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
          Retrying
          {code}
          Execution result
          {code}
          Finished: SUCCESS
          {code}
           
          h2. Examples to reproduce the issue
          h3. Failing example
          {code:java}
          node {
              def timeoutSeconds = 3
              stage('Preparation') { // for display purposes
                  retry(3){
                      timeout(activity: true, time: 2, unit: 'SECONDS') {
                          sleep(timeoutSeconds)
                      }
                      timeoutSeconds--
                  }
             }
          }
          {code}

          h3. Working example
          {code:java}
          node {
              def timeoutSeconds = 3
              stage('Preparation') { // for display purposes
                  retry(3){
                      try{
                          timeout(activity: true, time: 2, unit: 'SECONDS') {
                              sleep(timeoutSeconds)
                          }
                      }catch(err){
                          timeoutSeconds--
                          script{
                            def user = err.getCauses()[0].getUser()
                            error "[${user}] catched timeout! $err"
                          }
                      }
                  }
             }
          }
          {code}

            basil Basil Crow
            daconstenla David Constenla
            Votes:
            11 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: