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

Run.save called inside Run.onLoad by migrator

XMLWordPrintable

      I ran 1.609.3 with Workflow 1.10 and some other plugin updates on an existing $JENKINS_HOME with a job containing

          <org.jenkinsci.plugins.uniqueid.impl.JobIdStore_-JobIdProperty plugin="unique-id@1.2">
            <id>
              <id>...</id>
            </id>
          </org.jenkinsci.plugins.uniqueid.impl.JobIdStore_-JobIdProperty>
      

      and builds with unique-id.txt and

          <org.jenkinsci.plugins.uniqueid.impl.Id plugin="unique-id@1.2">
            <id>...</id>
          </org.jenkinsci.plugins.uniqueid.impl.Id>
      

      and got

      ... hudson.model.Run onLoad
      WARNING: failed to load org.jenkinsci.plugins.uniqueid.impl.Id@... from /.../jobs/.../builds/1/build.xml
      org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2$IDStoreMigrationException: Failure whilst migrating ... #1
      	at org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2.migrate(IdStoreMigratorV1ToV2.java:100)
      	at org.jenkinsci.plugins.uniqueid.impl.Id.onLoad(Id.java:78)
      	at hudson.model.Run.onLoad(Run.java:349)
      	at org.jenkinsci.plugins.workflow.job.WorkflowRun.onLoad(WorkflowRun.java:373)
      	at hudson.model.RunMap.retrieve(RunMap.java:223)
      	at ...
      	at jenkins.model.lazy.LazyLoadRunMapEntrySet$1.next(LazyLoadRunMapEntrySet.java:63)
      	at java.util.AbstractMap$2$1.next(AbstractMap.java:396)
      	at org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2$RunIDMigrationThread.run(IdStoreMigratorV1ToV2.java:137)
      	at java.lang.Thread.run(Thread.java:745)
      Caused by: java.lang.RuntimeException: Failed to serialize org.jenkinsci.plugins.workflow.job.WorkflowRun#execution for class org.jenkinsci.plugins.workflow.job.WorkflowRun
      	at hudson.util.RobustReflectionConverter$2.writeField(RobustReflectionConverter.java:214)
      	at ...
      	at com.thoughtworks.xstream.XStream.toXML(XStream.java:988)
      	at hudson.XmlFile.write(XmlFile.java:178)
      	at hudson.model.Run.save(Run.java:1898)
      	at org.jenkinsci.plugins.uniqueid.impl.RunIdStore.remove(RunIdStore.java:33)
      	at org.jenkinsci.plugins.uniqueid.impl.RunIdStore.remove(RunIdStore.java:18)
      	at org.jenkinsci.plugins.uniqueid.impl.LegacyIdStore.removeId(LegacyIdStore.java:83)
      	at org.jenkinsci.plugins.uniqueid.impl.IdStoreMigratorV1ToV2.migrate(IdStoreMigratorV1ToV2.java:90)
      	... 14 more
      Caused by: java.lang.NullPointerException
      	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$ConverterImpl.marshal(CpsFlowExecution.java:835)
      	at hudson.util.XStream2$AssociatedConverterImpl.marshal(XStream2.java:358)
      	at ...
      

      What seems to be happening: CpsFlowExecution.heads is null. Normally this is set either when creating a new build, or when restoring a build in initializeStorage, called from onLoad, called in turn from WorkflowRun.onLoad. However that first calls super.onLoad, which calls onLoad of each RunAction2, including Id. Fine, except that in turn does some stuff which ultimately calls Run.save, before Run.onLoad has even completed! So the WorkflowRun is being asked to save its state before it has finished initializing its own state.

      Could perhaps be worked around in Workflow, but this feels to me like a design problem in unique-id: it should not be asking to save a Run until that build has been fully loaded. This seems like a straightforward fix to make: just have RunIDMigrationThread collect a list of builds that ought to be saved, and do the saving after the loading, rather than from inside RunIdStore.remove.

      Might be able to use BulkChange here; not sure.

            amuniz Antonio Muñiz
            jglick Jesse Glick
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: