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

Race-condition when checking out global library

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • workflow-cps-global-lib:2.5
      Jenkins:2.19.4

      It seems like PR:18 introduced a race-condition when you have several builds of the same job starting at the same time.
      Looking at the code in the pull request:

      try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) {
          delegate.checkout(run, dir, listener, node.createLauncher(listener));
          // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care?
          // Copy sources with relevant files from the checkout:
          dir.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target);
      }
      

      We changed from using acquire to using allocate, which is non-blocking and instead append a suffix to the path if needed. The only problem with the change is that we still use the base directory given to allocate and ignoring the fact that we might have allocated another directory. Instead we should use lease.path, which is what we actually leased!

      So the code should probably be in the lines of:

      try (WorkspaceList.Lease lease = computer.getWorkspaceList().allocate(dir)) {
          delegate.checkout(run, lease.path, listener, node.createLauncher(listener));
          // Cannot add WorkspaceActionImpl to private CpsFlowExecution.flowStartNodeActions; do we care?
          // Copy sources with relevant files from the checkout:
          lease.path.copyRecursiveTo("src/**/*.groovy,vars/*.groovy,vars/*.txt,resources/", null, target);
      }
      

            jons Jon Sten
            jons Jon Sten
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: