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

FileAlreadyExistsException upon "deleted" symlink while (re)creating it

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Similar Issues:

      Description

      Some Jenkins instances of ours do log FileAlreadyExistsException-s from time to time:

      java.nio.file.FileAlreadyExistsException: (path2onesJob)/lastSuccessful
      at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
      (..) at hudson.Util.createSymlinkJava7(Util.java:1122)
      (..)

      -Above trace mapping to 1.509.2.
      Code shows "proper" deletion of symlink prior to (re)creating it:
      (..)
      filesC.getMethod("deleteIfExists", pathC).invoke(null, path);
      Object noAttrs = Array.newInstance(Class.forName("java.nio.file.attribute.FileAttribute"), 0);
      filesC.getMethod("createSymbolicLink", pathC, pathC, noAttrs.getClass()).invoke(null, path, target, noAttrs);

      -Looking at that code and around,
      I suspect some occasional race condition by lack of concurrency safeness:
      1. thread-A deletes any existing lastSuccessful symlink (so far so good)
      2. thread-B deletes it too but that is a no-op by now, given 1.
      3. thread-A (re)creates the symlink (no problem yet)
      4. thread-B recreates the symlink, but that throws our hereby exception, given 3. (problematic).

      -Unless such initial deletion fails because of this:
      "On some operating systems it may not be possible to remove a file when it is open and in use by this Java virtual machine or other programs."
      http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#deleteIfExists(java.nio.file.Path)

      -Assuming the above threading hypothesis and solving it to be hard & risky.

        Attachments

          Activity

          Hide
          dogfood dogfood added a comment -

          Integrated in jenkins_main_trunk #3060
          [FIXED JENKINS-20610] symlink FileAlreadyExistsException (Revision d0f84c2e5314eb1f6448f0aa325e75adbfba020c)
          JENKINS-20610 Noting merge of #1019. (Revision 65548d138158faff02c8000fb422080e650eeaf7)

          Result = UNSTABLE
          marco.miller : d0f84c2e5314eb1f6448f0aa325e75adbfba020c
          Files :

          • core/src/main/java/hudson/Util.java

          Jesse Glick : 65548d138158faff02c8000fb422080e650eeaf7
          Files :

          • changelog.html
          Show
          dogfood dogfood added a comment - Integrated in jenkins_main_trunk #3060 [FIXED JENKINS-20610] symlink FileAlreadyExistsException (Revision d0f84c2e5314eb1f6448f0aa325e75adbfba020c) JENKINS-20610 Noting merge of #1019. (Revision 65548d138158faff02c8000fb422080e650eeaf7) Result = UNSTABLE marco.miller : d0f84c2e5314eb1f6448f0aa325e75adbfba020c Files : core/src/main/java/hudson/Util.java Jesse Glick : 65548d138158faff02c8000fb422080e650eeaf7 Files : changelog.html
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -
          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: changelog.html http://jenkins-ci.org/commit/jenkins/65548d138158faff02c8000fb422080e650eeaf7 Log: JENKINS-20610 Noting merge of #1019. Compare: https://github.com/jenkinsci/jenkins/compare/1067585a4951...65548d138158
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Marco Miller
          Path:
          core/src/main/java/hudson/Util.java
          http://jenkins-ci.org/commit/jenkins/d0f84c2e5314eb1f6448f0aa325e75adbfba020c
          Log:
          [FIXED JENKINS-20610] symlink FileAlreadyExistsException

          Retrying 3 times while waiting for 100 millis between retries (at
          recreating symlink after "deleting" it). Ends up throwing FAE exception
          if thrown for a 4th time in a row - as not much can be done at that
          point. A warning is logged in that case, prior to throwing the last FAE.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Marco Miller Path: core/src/main/java/hudson/Util.java http://jenkins-ci.org/commit/jenkins/d0f84c2e5314eb1f6448f0aa325e75adbfba020c Log: [FIXED JENKINS-20610] symlink FileAlreadyExistsException Retrying 3 times while waiting for 100 millis between retries (at recreating symlink after "deleting" it). Ends up throwing FAE exception if thrown for a 4th time in a row - as not much can be done at that point. A warning is logged in that case, prior to throwing the last FAE.

            People

            Assignee:
            marcomiller Marco Miller
            Reporter:
            marcomiller Marco Miller
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: