-
Bug
-
Resolution: Fixed
-
Major
-
None
-
Jenkins 1.554.1
GerritTrigger 2.11.1
When viewing jobs, newer builds disappear from the build history list. Trying to go to the URL of a newer build results in a 404. The missing builds are located on disk and restarting Jenkins will make them reappear.
Sometimes, the nextBuildNumber is set to a lower number and duplicate builds are created; two date-directories are created in builds/ but only the latest build has a build_number symlink.
I wrote tool to help detect these problems on disk and even repair them (for some value of repair): https://github.com/docwhat/jenkins-job-checker
A lot of history is on JENKINS-15156; I'll repeat some of it below.
- is blocked by
-
JENKINS-42511 Computed Folder API poorly designed for concurrent event processing
-
- Closed
-
- is related to
-
JENKINS-15156 Builds disappear from build history after completion
-
- Resolved
-
-
JENKINS-10709 multiple builds are triggered for one change in Gerrit
-
- Resolved
-
-
JENKINS-23130 nextBuildNumber keeps being set to previous numbers
-
- Resolved
-
-
JENKINS-25962 Using Jenkins Job Builder to create triggers based on comment regex fails to trigger
-
- Reopened
-
-
JENKINS-27530 ISE from RunMap.put after reloading configuration from disk
-
- Resolved
-
-
JENKINS-26582 ISE from RunMap.put using /git/notifyCommit on a matrix project
-
- Closed
-
-
JENKINS-24380 Use build numbers as IDs
-
- Resolved
-
- links to
[JENKINS-23152] builds getting lost due to GerritTrigger
My current theory is that either:
1) The list-of-builds is being modified by something
2) A new list-of-builds is being created at certain times (e.g. "Reload Configuration from Disk") and some things are still using the old list-of-builds. This causes the weird mis-match and possibly explains how nextBuildNumber gets "reset" to an older version. Possibly the object that is recreated is the Project itself (which holds the nextBuildNumber).
I think #2 is the more likely.
I am willing to help solve this; what I am stuck on is just reproducing the problem, specifically getting Gerrit configured to the point where it triggers something (since I am not a Gerrit user and its configuration seems rather complex). Is there perhaps some method in the Gerrit Trigger plugin I could call from the script console which would simulate the trigger from a Gerrit server without actually running anything besides Jenkins? That would be the starting point for a regression test anyway. But I will ask @schristou about this too.
I'm willing to pair with you to reproduce (and even fixing the bug).
It appears that the "Query and Trigger Gerrit" thingy actually produces a slightly different bug.
I think what we can do is point it at a Gerrit repository and have the job trigger on any Gerrit change... but we have to find a Gerrit repository you have permission to "listen to the event streams" on.
Reproduced. From code review, both BuildMemory and GerritTrigger appear to be storing (indirect) references to Job instances in global static state, which is not permissible. Looking into a fix; probably cannot test any fix very realistically other than to confirm that it solves the observed problem and does not regress tests, but that is what a PR is for.
After reloading from disk, and seeing a lack of builds, took a heap dump with jmap and analyzed in the NetBeans profiler. There are indeed two FreeStyleProject instances with the same name. The second is the reloaded one, but the old one is still there; GC root reference analysis confirms my suspicions:
this - value: hudson.model.FreeStyleProject #1 <- myProject - class: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger, value: hudson.model.FreeStyleProject #1 <- [2] - class: java.lang.Object[], value: com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger #1 <- array - class: java.util.concurrent.CopyOnWriteArrayList, value: java.lang.Object[] #44424 <- al - class: java.util.concurrent.CopyOnWriteArraySet, value: java.util.concurrent.CopyOnWriteArrayList #137 <- gerritEventListeners - class: com.sonyericsson.hudson.plugins.gerrit.trigger.GerritHandlerLifecycle, value: java.util.concurrent.CopyOnWriteArraySet #3 <- coordinator (thread object) - class: com.sonymobile.tools.gerrit.gerritevents.workers.EventThread, value: com.sonyericsson.hudson.plugins.gerrit.trigger.GerritHandlerLifecycle #1
Should "myProject" be deprecated? Trigger has a member "job" as reference to project.
That's why I would like to see stop and start being called on triggers when reload from disk happens, there is no other hook, that I know of, for the trigger to realize that it is happening so that it can clear out the listeners list of old objects.
So you can try https://jenkins.ci.cloudbees.com/job/plugins/job/gerrit-trigger-plugin/266/com.sonyericsson.hudson.plugins.gerrit$gerrit-trigger/artifact/com.sonyericsson.hudson.plugins.gerrit/gerrit-trigger/2.12.0-beta-3-SNAPSHOT/gerrit-trigger-2.12.0-beta-3-SNAPSHOT.hpi which I think solves the issue. Unfortunately the plugin’s tests as currently written cannot handle the kind of change I needed to make, so the PR cannot be merged in its current form.
Should "myProject" be deprecated? Trigger has a member "job" as reference to project.
One of the commits in the PR fixed that.
@rsandell as noted in the PR comments, while expanding the calls made to Trigger.stop from core might fix the bug as produced by Reload Configuration from Disk, other problematic cases will likely remain—folder moves, etc.—and you will be tracking them all down for a long time. The root problem is that GerritTrigger and related classes hold references to AbstractProject yet are used in global static state, which is inherently risky and a design problem: items are intended by held only from their ItemGroup (ultimately via the Jenkins singleton). I believe my PR corrects that problem, or at least gives the general idea, but the plugin tests would need extensive edits to keep up.
Code changed in jenkins
User: Robert Sandell
Path:
pom.xml
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemory.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTimerTask.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/24c7b25dbf75925379480f0cbfda8903c0d336db
Log:
Merge branch 'reload-JENKINS-23152' of github.com:jglick/gerrit-trigger-plugin into JENKINS-23152
Conflicts:
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
Hi,
This is becoming a real mess for us as gerrit keeps referring to the builds that are not showing in the Jenkins GUI and all build numbers are getting messed up. Can the fix be somehow pushed forward?
Thanks!
I am working on a fix on this branch https://github.com/jenkinsci/gerrit-trigger-plugin/tree/JENKINS-23152 and am close to done. It should be ready enough for beta testing if you can build it yourself.
Still have a bunch of findbugs issues to fix and get feedback from the other maintainers since this fix does fundamental changes in the plugin.
It is a good idea to create a PR from the branch—makes it easier for people to comment on individual diff lines.
Code changed in jenkins
User: Robert Sandell
Path:
pom.xml
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpander.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListener.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemory.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/UnreviewedPatchesListener.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/events/PluginDraftPublishedEvent.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/replication/ReplicationCache.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/replication/ReplicationQueueTaskDispatcher.java
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritManagement/index_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritManagement/newServer_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/index_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServer/remove_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/Messages.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/Messages_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritCause/description_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config.jelly
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger/config_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerAction/ajaxTriggerMonitor_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerAction/help-Search_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/actions/manual/ManualTriggerAction/index_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/events/PluginCommentAddedContainsEvent/config_ja.properties
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/events/PluginDraftPublishedEvent/config.jelly
src/main/resources/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/events/PluginPatchsetCreatedEvent/config_ja.properties
src/main/webapp/help-GerritNoConnectionOnStartup_ja.html
src/main/webapp/help-GerritNotificationLevel_ja.html
src/main/webapp/help-GerritServerName_ja.html
src/main/webapp/help-ReplicationCacheExpiration_ja.html
src/main/webapp/help-ReplicationSlaveHost_ja.html
src/main/webapp/help-ReplicationSlaveName_ja.html
src/main/webapp/help-ReplicationSlaveTimeout_ja.html
src/main/webapp/help-Replication_ja.html
src/main/webapp/help-defaultSlave_ja.html
src/main/webapp/help-enableSlaveSelectionInJobs_ja.html
src/main/webapp/trigger/help-DependencyJobs_ja.html
src/main/webapp/trigger/help-DraftPublished.html
src/main/webapp/trigger/help-DraftPublished_ja.html
src/main/webapp/trigger/help-ExcludeNoCodeChange_ja.html
src/main/webapp/trigger/help-ExcludeTrivialRebase_ja.html
src/main/webapp/trigger/help-ReadableMessage_ja.html
src/main/webapp/trigger/help-SilentStartMode.html
src/main/webapp/trigger/help-TriggerUnreviewedPatches_ja.html
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritServerHudsonTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/api/GerritTriggerApiTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ParameterExpanderTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritProjectListTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/DuplicatesUtil.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/MockGerritHudsonTriggerConfig.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/Setup.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/mock/TestUtils.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/replication/ReplicationQueueTaskDispatcherTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/BackCompat252HudsonTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
src/test/java/com/sonymobile/tools/gerrit/gerritevents/mock/SshdServerMock.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/3084c3ec6cf394ca598844337a086402c0e059ff
Log:
Merge remote-tracking branch 'origin/master' into JENKINS-23152
Conflicts:
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemory.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
Tests compiles but still fails.
Code changed in jenkins
User: Robert Sandell
Path:
pom.xml
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/PluginImpl.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemory.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/EventListener.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTimer.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTimerTask.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritUserCause.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/UnreviewedPatchesListener.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/dependency/DependencyQueueTaskDispatcherTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/ToGerritRunListenerTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/rest/BuildCompletedRestCommandJobHudsonTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemoryTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/MemoryImprintTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTriggerTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/replication/ReplicationQueueTaskDispatcherTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersHudsonTestCase.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/DuplicateGerritListenersPreloadedProjectHudsonTestCase.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/gerritnotifier/SpecGerritVerifiedSetterTest.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/c3899eaf4e05a43430b332c628e17f82964eda1a
Log:
Merge pull request #193 from jenkinsci/JENKINS-23152
Fix for JENKINS-23152
Compare: https://github.com/jenkinsci/gerrit-trigger-plugin/compare/19bfb019b070...c3899eaf4e05
@rsandell Could you please provide a link to download the HPI file? Thanks!
You can get it from the experimental update center http://jenkins-ci.org/content/experimental-plugins-update-center
Direct download would be http://repo.jenkins-ci.org/releases/com/sonyericsson/hudson/plugins/gerrit/gerrit-trigger/2.13.0-beta-2/gerrit-trigger-2.13.0-beta-2.hpi
installed the latest version - thanks for the link!
Will watch it for a while...
We tested this on core: Jenkins ver. 1.580.3, and Gerrit event triggered doesn't show up until 'Anonymous' has "Read" and "Discover" access on jobs
Catalina.out:
Feb 04, 2015 3:03:19 AM com.sonymobile.tools.gerrit.gerritevents.GerritHandler notifyListeners
SEVERE: Notify-error:
org.acegisecurity.AccessDeniedException: Please login to access job <jenkinsJob_name>
at jenkins.model.Jenkins.getItem(Jenkins.java:2323)
at jenkins.model.Jenkins.getItem(Jenkins.java:307)
at jenkins.model.Jenkins.getItemByFullName(Jenkins.java:2429)
at com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener.getTrigger(EventListener.java:278)
at com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.EventListener.gerritEvent(EventListener.java:79)
at com.sonymobile.tools.gerrit.gerritevents.GerritHandler.notifyListener(GerritHandler.java:299)
at com.sonymobile.tools.gerrit.gerritevents.GerritHandler.notifyListeners(GerritHandler.java:276)
at com.sonyericsson.hudson.plugins.gerrit.trigger.GerritHandlerLifecycle.notifyListeners(GerritHandlerLifecycle.java:63)
at com.sonymobile.tools.gerrit.gerritevents.workers.AbstractGerritEventWork.perform(AbstractGerritEventWork.java:46)
at com.sonymobile.tools.gerrit.gerritevents.workers.AbstractJsonObjectWork.perform(AbstractJsonObjectWork.java:77)
at com.sonymobile.tools.gerrit.gerritevents.workers.StreamEventsStringWork.perform(StreamEventsStringWork.java:67)
at com.sonymobile.tools.gerrit.gerritevents.workers.EventThread.run(EventThread.java:66)
Why would the changes for this bug have affected permissions? Seems like a mistake. Normally listeners and background threads need to run under ACL.impersonate(ACL.SYSTEM).
I remember some change in core a while back where the default user was changed from SYSTEM to anonymous. And this is the first time that the plugin has started to do item lookups instead of direct references and all tests has been done on an unsecured Jenkins, so I think its legit.
Code changed in jenkins
User: Scott Hebert
Path:
pom.xml
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritHandlerLifecycle.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JenkinsAwareGerritHandler.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/PluginImpl.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/SystemEventThread.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/GerritHandlerLifecycleTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/JenkinsAwareGerritHandlerTest.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/LockedDownGerritEventTest.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/1740c39ae13fdee400ab03caef588c2d4dd069d2
Log:
Enable background threads to impersonate SYSTEM
Jenkins plugin listeners and background threads should normally run as the SYSTEM user.
This commit allows the EventThreads to impersonate ACL.SYSTEM
Addresses regression in JENKINS-23152
Change-Id: Ia0f5a223f70497ad44529c390aff0c711e414f67
Code changed in jenkins
User: Scott Hebert
Path:
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/ssh/BuildCompletedCommandJob.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/job/ssh/BuildStartedCommandJob.java
src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/LockedDownGerritEventTest.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/a03c0d5da9cc4d275e4984ca1c8e035f1d6056d2
Log:
Gerrit notifier threads should impersonate SYSTEM
The BuildCompletedCommandJob was not impersonating SYSTEM and was
therefore throwing permission-related exceptions.
For completeness, BuildStartedCommandJob was updated too.
Related to JENKINS-23152
Change-Id: I3eb6036d8186478a615c15036b4b7f98035dd54c
Code changed in jenkins
User: Scott Hebert
Path:
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/gerritnotifier/model/BuildMemory.java
src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/EventListener.java
http://jenkins-ci.org/commit/gerrit-trigger-plugin/5604387839ef68c42f22517a262f639fd4f1f111
Log:
Correct infinite loops caused by CommentAdded
CommentAdded events were not be processed with the correct
gerritEvent() signature. This caused builds be triggered needlessly
and sometimes caused infinite loops between Jenkins and Gerrit.
This fix exposes the EventListener as a public class so that the Gerrit Events
Gerrit Handler can correctly invoke the appropriate methods.
This also corrects a NPE during a BuildStarted notification.
Change-Id: Ief95fc05d5cf0a5d2e0dc95330e74bb6d52f425c
I can't tell what action has been taken on this defect recently. I installed http://repo.jenkins-ci.org/releases/com/sonyericsson/hudson/plugins/gerrit/gerrit-trigger/2.13.0-beta-2/gerrit-trigger-2.13.0-beta-2.hpi on my Jenkins server and, although it did seem to fix the "missing builds" issue, now I'm only getting one of multiple jobs reporting results back to Gerrit! When I submit a patch set to our Gerrit server, I only get one email but that email shows just one job that was triggered but indicates that the job triggered is 1 of 2. When I go to the review in Gerrit, it only shows one of the two jobs being triggered. This is what I see in Gerrit:
jenkins
12:32 PM
↩
Patch Set 1:
Build Started http://jenkins-instance:8080/job/test-2/37/ (2/2)
I should be seeing:
jenkins
12:32 PM
↩
Patch Set 1:
Build Started http://jenkins-instance:8080/job/test-1/37/ (1/2)
Build Started http://jenkins-instance:8080/job/test-2/37/ (2/2)
I see this with 2.13 beta 2 through 5. I tried 2.13 beta 6 and it fixed this but then I ran into the missing builds defect again.
Has anyone else seen this? I could use some suggestions. This is preventing us from putting our upgraded Jenkins instances into our production environment.
@Katherine Can you provide some more information? e.g. what does your configuration look like, do you see any warnings or severe logs in the server log etc.
after activating ntp on all slaves and master nodes, the problem seems to be resolved. maybe someone else can confirm if this workaround resolves the issue.
FWIW, same or similar issue seen here too on Jenkins 1.593 (+Jenkins Gerrit plugin 2.12.0 and a 2.8.3 Gerrit server). It seems to have happened since we used reload from disk (which we do only few times a year) and only affects Gerrit builds.
Even when triggered manually with the "query & trigger Gerrit Patches", we see the new build displayed on the left of the screen. But it does not appear in the job page and leads to a 404 when accessed. And the build is indeed on the disk and seems to run just fine. So more something like a GUI issue.
Will post more informations here if we manage to reproduce the issue non randomly.
And what happens if you upgrade to >= 2.13 where efforts have been made to fix this?
rsandell We plan to upgrade our instance quite soon, we'll see it this comes back. Thanks for the feedback.
Summary of the IRC chat:
On IRC schristou said that he tracked this down to GerritTrigger...
Specifically, his steps to reproduce are to "Reload Configuration from Disk" and then kick off a Gerrit build.
The nextBuildNumber was new to GerritTrigger author rsandell; "It could have something to do with cancel previous patchsets, but I'm just guessing".
I'm also fairly certain its happening to us even without "Reload Configuration from Disk" because we normally don't use that (we've been using Jenkins since the days when build info would be lost and are afraid of it).
rsandell mentioned that core not sending a start/stop signal to the triggers when a reload from disk is performed makes it very hard for him to make GerritTrigger behave better.