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

Improve locking around jenkins.branch.MultiBranchProject.getProjectFactory

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • branch-api-plugin
    • None
    • 2.1200.v4b_a_3da_2eb_db_4

      The Branch API has a synchronized method to access the ProjectFactory of a Multibranch project jenkins.branch.MultiBranchProject.getProjectFactory:

      That method is used in many scenario and that includes from hudson.model.AbstractItem.getRootDir through the ChildNameGenerator:

          at jenkins.branch.MultiBranchProject.getProjectFactory(MultiBranchProject.java:343)
          ### Above call has no need to synchronize, the value is guaranteed to be non-null.
          at jenkins.branch.MultiBranchProjectDescriptor$ChildNameGeneratorImpl.dirNameFromItem(MultiBranchProjectDescriptor.java:244)
          at jenkins.branch.MultiBranchProjectDescriptor$ChildNameGeneratorImpl.dirNameFromItem(MultiBranchProjectDescriptor.java:222)
          at com.cloudbees.hudson.plugins.folder.ChildNameGenerator.dirName(ChildNameGenerator.java:198)
          at com.cloudbees.hudson.plugins.folder.AbstractFolder.getRootDirFor(AbstractFolder.java:538)
          at jenkins.branch.MultiBranchProject.getRootDirFor(MultiBranchProject.java:870)
          at jenkins.branch.MultiBranchProject.getRootDirFor(MultiBranchProject.java:130)
          at hudson.model.AbstractItem.getRootDir(AbstractItem.java:201)
      

      This can cause some contention and deadlocks in scenario where a process loops through multibranch children (linked issues) or items are loaded / reloaded. Though most of the time the locking is not necessary since a ProjectFactory is not often updated..

      The point being that we expect the ProjectFactory to be initialized once and that's when we need synchronization. dnusbaum mentioned that double-checked locking would be better suited here by for example making the field volatile and and only synchronize on this when the field is being initialized.

          [JENKINS-74777] Improve locking around jenkins.branch.MultiBranchProject.getProjectFactory

          Allan BURDAJEWICZ created issue -
          Allan BURDAJEWICZ made changes -
          Issue Type Original: Bug [ 1 ] New: Improvement [ 4 ]
          Devin Nusbaum made changes -
          Link New: This issue relates to JENKINS-73715 [ JENKINS-73715 ]
          Devin Nusbaum made changes -
          Link New: This issue relates to JENKINS-72678 [ JENKINS-72678 ]
          Basil Crow made changes -
          Assignee New: Basil Crow [ basil ]
          Basil Crow made changes -
          Remote Link New: This issue links to "jenkinsci/branch-api-plugin#494 (Web Link)" [ 30145 ]
          Basil Crow made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Basil Crow made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Basil Crow made changes -
          Released As New: 2.1200.v4b_a_3da_2eb_db_4
          Resolution New: Fixed [ 1 ]
          Status Original: In Review [ 10005 ] New: Closed [ 6 ]
          Allan BURDAJEWICZ made changes -
          Remote Link New: This issue links to "CloudBees Internal Issue (Web Link)" [ 30416 ]

            basil Basil Crow
            allan_burdajewicz Allan BURDAJEWICZ
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: