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

Locking a resource while holding it locked in the same job is not possible

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins version 2.363, Lockable Resources plugin version 2.15. Windows 10.

      Locking a resource while holding it locked in the same job like this:

      lock(resource: 'res1'){
        sleep(time: 2, unit: 'SECONDS')
        lock(resource: 'res1'){
          sleep(time: 2, unit: 'SECONDS')
        }
      }
      

      results in indefinite wait:

      Trying to acquire lock on [res1]
      Resource [res1] did not exist. Created.
      Lock acquired on [res1]
      [Pipeline] {
      [Pipeline] sleep
      Sleeping for 2 sec
      [Pipeline] lock
      Trying to acquire lock on [res1]
      Found 0 available resource(s). Waiting for correct amount: 1.
      [res1] is locked by job-name #NN waiting...

      I would expect the inner lock to be granted immediately since the job has already acquired exclusive access to the resource.

          [JENKINS-70304] Locking a resource while holding it locked in the same job is not possible

          There is is a logic to skip locks used in same scope (but it can not work, because there are 2 scopes of cores). I will change it for long time ago, BUT it might break pipes, where is the step lock() used with labels, and you really want to lock it. To make all happy it shall be somehow configurable. Let me see. Maybe next release

          Martin Pokorny added a comment - There is is a logic to skip locks used in same scope (but it can not work, because there are 2 scopes of cores). I will change it for long time ago, BUT it might break pipes, where is the step lock() used with labels, and you really want to lock it. To make all happy it shall be somehow configurable. Let me see. Maybe next release

          Martin Pokorny added a comment - - edited

          hm?, This might be really tricky, when you make it in parallel stages.

          stages = [:]
          stages['hi1'] = 
          lock('ABC') {
           echo 'hi1'
          }
          stages['hi2'] = 
          lock('ABC') {
          echo 'hi2'
          }
          
          parallel stages

          Martin Pokorny added a comment - - edited hm?, This might be really tricky, when you make it in parallel stages. stages = [:] stages[ 'hi1' ] = lock( 'ABC' ) { echo 'hi1' } stages[ 'hi2' ] = lock( 'ABC' ) { echo 'hi2' } parallel stages

            Unassigned Unassigned
            epliskin Eugene Pliskin
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: