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

Locks within parallel tasks release other locks within the pipeline

XMLWordPrintable

      When a pipeline has an outer lock of a resource and then runs multiple tasks in parallel which have inner locks. The outer lock is sometimes prematurely cleared when the parallel tasks clear their inner lock.

      This bug was introduced in 1.11 and does not appear in 1.10

      A sample pipeline job is below. When the 1st parallel jobs completes, it releases the inner lock as expected. When the 2nd parallel job completes, it releases the inner lock but the outer lock is also cleared. This could be due to clean up code that is clearing a resource lock that it shouldn't be.

      node('master'){
        // outer lock here, this should persist until the end
        lock('outer') {
          sh "sleep 10"
          def stepsForParallel = [:]
          for (int i = 1; i <= 4; i++) {
            def stepName = "Inner Run - ${i}"
            stepsForParallel[stepName] = test()   
          }
          parallel stepsForParallel
          sh "sleep 10"
        }
      }
      
      def test() {
        return {
          // create an inner lock which the parallel tasks will queue around
          lock('inner') {
            sh "sleep 10"
          }
        }
      }
      

            Unassigned Unassigned
            marknysen Mark Nysen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: