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

Exclusion-Plugin does not release resource after job aborted

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • exclusion-plugin
    • None
    • windows

      [test case] -> this test case is similar as test case from JENKINS-12077
      // settings
      1. create matrix project
      2. create axis1 [a b], axis2 [c d]
      3. create LOCK-$EXPORTED_AXIS1
      4. Inject environment variables to the build process EXPORTED_AXIS1=$axis1
      5. add critical-block-start
      6. add windows batch command e.g. dir d:\ /s /b | find "lock"
      7. add critical-block-end
      // running
      8. run build -> #1
      9. run build and stop it -> #2
      10. run build it -> it causes 'deadlock' there is unreleased resource from build #2

      I write (locally) simple patch in IdAllocationManager.java which can works. It release resource from completed build whom downstream projects are also completed.

      new method:

      private void releaseDeadlockedResource(String id, BuildListener buildListener) throws InterruptedException, IOException {
      PrintStream logger = buildListener.getLogger();

      // check if 'lockable resource' exists
      AbstractBuild resourceOwner = ids.get(id);

      if (resourceOwner != null && !resourceOwner.isBuilding()) { // build was completed
      List<AbstractProject> downstreamProjects = resourceOwner.getProject().getDownstreamProjects();
      boolean canRelease = true;

      for (Iterator<AbstractProject> it = downstreamProjects.iterator(); it.hasNext() {
      AbstractProject proj = it.next();
      if (proj.isBuilding())

      { canRelease = false; break; }

      }
      if (canRelease)

      { logger.println("Release resource from completed build: " + resourceOwner.toString()); ids.remove(id); }

      }
      }

      and changes in allocate() method:

      public synchronized String allocate(AbstractBuild owner, String id, BuildListener buildListener) throws InterruptedException, IOException {

      PrintStream logger = buildListener.getLogger();

      boolean printed = false;
      while (ids.get(id) != null) {
      if (printed == false)

      { logger.println("Waiting ressource : " + id + " currently use by : " + ids.get(id).toString()); printed = true; }

      wait(1000);

      // periodically detect if any locked resource belongs to the completed build
      releaseDeadlockedResource(id, buildListener);
      }

      ids.put(id, owner);
      return id;
      }

            anthonyroux Anthony Roux
            ferda juraj fedorko
            Votes:
            4 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: