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

Gerrit server connection leaks when Jenkins Configuration as Code is used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • gerrit-trigger-plugin
    • None
    • Fixed since 2.36.1

      We observed a growing number of duplicate Gerrit event stream connections (SSH) to our Gerrit servers from individual Jenkins deployments. Not only does this put additional load on the Gerrit server, but this also means the Gerrit Trigger plugin has to process multiple copies of identical JSON events (you can see these when you enable debug logging). Eventually we tracked this down to use of the "Jenkins Configuration as Code" plugin to configure the servers specified for the Gerrit Trigger plugin, run from a pipeline each time that a configuration change is merged. The problem occurs within the "configure()" method of the "GerritJcascConfigurator" class. Specifically, on line 94 it attempts to save the old list of "GerritServer" instances:

              List<GerritServer> oldServers = instance.getServers();
      

      However, that statement is assigning a reference to the returned list, not a new list with the same elements. After the base class "configure()" method is called, the list has been updated with the new server instance(s). But because "oldServers" is a reference, it also now points at the new instances. So the following code attempts to stop the new server instances (which aren't running yet) instead of the old ones as intended:

              for (GerritServer oldServer : oldServers) {
                  oldServer.stopConnection();
                  oldServer.stop();
              }
      

      And you see a corresponding error in the log:

      Jul 16, 2022 6:11:32 PM com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer stopConnection
      WARNING: Was told to shutdown again?
      

      Another minor issue is that the "dryrun" flag isn't observed, which means that during the first call to "configure()" when no changes are saved, it unnecessarily restarts the existing server instances.

            rsandell rsandell
            chrisa_arm Chris
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: