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

p4-plugin keeps opening connection during the build. Causing long delays

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: p4-plugin
    • Labels:
    • Environment:
      Pipeline scripted
      p4 plugin v 1.9.2 (latest)
      Both on Jenkins 2.107.3 and 2.138.2.
      Also on clean installed Jenkins server
    • Similar Issues:

      Description

      After using the p4 plugin, and after it finished its task, the p4 plugin keeps opening connection and closing it. Each such action takes 1-2 seconds. So during the rest of the build, there is a delay of 5-20 seconds between the commands.

      How to reproduce:

      1. Go to <jenkins url>/log/ and add a new logger called "p4"
        Logger = "org.jenkinsci.plugins.p4" ; Log level = "ALL"
      2. Create a pipeline job with this script:
      node() {
          // library retriever: legacySCM(perforce( // fill your data here.
          // p4sync // fill your data here.
          stage('run') {
              3.times {
                  sh 'date'
              }
          }
      }
      1. Build the Job
      2. Now remove one of the commented lines (library with perforce or p4sync), fill the needed data. You can use the "Pipeline Syntax".
      3. Build the Job again
      4. Compare the time that the 'run' stage took:
        1. in step 3 it took ~350 ms
        2. in step 5 it took 53 seconds
          and this time diff is only for 3 "sh" calls. For longer jobs it increases.
      5. Pay attention that this time is only for the 3 calls to "sh", and not including the p4 stage.
      6. Open the log you created at stage 1 (<jenkins url>/log/p4).
        You can see there a loop of
            P4: opened connection OK
            P4: closed connection OK
        Each "open" takes 1-2 seconds, and during this time the build can't proceed.

        Attachments

          Activity

          Hide
          p4paul Paul Allen added a comment -

          It looks like buildEnvironment(Run<?, ?> run, Map<String, String> env) is getting called many times by Jenkins.  Normally this would not be a problem, however there is an environment variable P4_TICKET which was cached in the XML config, but now looked up on demand.  I have cached this in a transient variable which will reduce the number of calls to P4D.

          https://ci.jenkins.io/job/Plugins/job/p4-plugin/job/master/287/ (assuming the build passes)

          Jenkins > Manage Jenkins > Manage Plugins > Advanced tab > Upload Plugin > Select HPI file > Upload > Restart

          Show
          p4paul Paul Allen added a comment - It looks like buildEnvironment(Run<?, ?> run, Map<String, String> env)  is getting called many times by Jenkins.  Normally this would not be a problem, however there is an environment variable P4_TICKET which was cached in the XML config, but now looked up on demand.  I have cached this in a transient variable which will reduce the number of calls to P4D. https://ci.jenkins.io/job/Plugins/job/p4-plugin/job/master/287/  (assuming the build passes) Jenkins > Manage Jenkins > Manage Plugins > Advanced tab > Upload Plugin > Select HPI file > Upload > Restart
          Hide
          erez_arbell Erez Arbell added a comment -

          Awesome! It fixed the issue. Now the stage takes the same time as without using p4, and the redundant open connections stopped.

          My pipeline is much faster now. Also, the duration of the "p4 sync" itself reduced to 60% than it was before.

          Thank you.

          Show
          erez_arbell Erez Arbell added a comment - Awesome! It fixed the issue. Now the stage takes the same time as without using p4, and the redundant open connections stopped. My pipeline is much faster now. Also, the duration of the "p4 sync" itself reduced to 60% than it was before. Thank you.
          Hide
          p4paul Paul Allen added a comment -

          Ready for release.

          Show
          p4paul Paul Allen added a comment - Ready for release.
          Hide
          p4paul Paul Allen added a comment -

          Thank you for trying this out, I'm pleased it resolved your issue.  I have marked this 'ready for release' and it should be officially available in the next few days.

          Show
          p4paul Paul Allen added a comment - Thank you for trying this out, I'm pleased it resolved your issue.  I have marked this 'ready for release' and it should be officially available in the next few days.
          Hide
          p4paul Paul Allen added a comment -

          Released in 1.9.3

          Show
          p4paul Paul Allen added a comment - Released in 1.9.3

            People

            • Assignee:
              p4paul Paul Allen
              Reporter:
              erez_arbell Erez Arbell
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: