Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from readResolve to unmarshal #528

Merged
merged 3 commits into from
Apr 25, 2022

Conversation

car-roll
Copy link
Contributor

@car-roll car-roll commented Apr 24, 2022

If a build is loaded from a saved state, and the build existed before #519 (i.e. v2686.v7c37e0578401), It is possible for the timings field to be NULL. This causes an NPE when the Timing is closed:

timings.merge(kind.name(), System.nanoTime() - start, Long::sum);

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

@car-roll car-roll added the bug label Apr 24, 2022
@Override public void close() {
// it is possible for timings to be null if an old build (< v2686.v7c37e0578401) is being loaded from a saved state
if (timings == null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I basically just put back the null check that was removed in #519

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this addition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes, removed in #529

@car-roll car-roll requested review from jglick, Vlatombe, dwnusbaum and a team April 24, 2022 05:27
@Vlatombe
Copy link
Member

Vlatombe commented Apr 25, 2022

I wonder if this is not a symptom of inconsistent (or at least, surprising) deserialization, where unmarshal is called but not readResolve. Should the current unmarshal method be patched to call readResolve at the end?

@dwnusbaum
Copy link
Member

I wonder if this is not a symptom of inconsistent (or at least, surprising) deserialization, where unmarshal is called but not readResolve.

I tested this really quickly by adding logger calls in each method, and it does look like only unmarshal gets called during deserialization.

Should the current unmarshal method be patched to call readResolve at the end?

Maybe? I took a quick look through xstream to see if there was any discussion or documentation about combining custom converters with readResolve, but I did not notice anything. I could also see an argument for moving the logic in readResolve into unmarshal and deleting readResolve, at least as long as that doesn't cause any other issues.

@jglick
Copy link
Member

jglick commented Apr 25, 2022

moving the logic in readResolve into unmarshal and deleting readResolve

That sounds appropriate.

@car-roll
Copy link
Contributor Author

When I move the code to

timings is still null.

Looking at the stack trace, I realize it is only calling WorkflowRun.reload(): https://github.com/jenkinsci/workflow-job-plugin/blob/04c4e75dce438ba5af785fbf3a7711cacd54f41e/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowRun.java#L538
So it is completely bypassing CpsFlowExecution.unmarshal() and just calling hudson.XmlFile.unmarshal via WorkflowJob.getLastBuild()

@dwnusbaum
Copy link
Member

@car-roll I think you would need to inline readResolve later on (e.g. right before the return statement), not add the logic into the else if block, because if timings is missing from the XML file (i.e. if it is null), that block never gets entered.

@car-roll
Copy link
Contributor Author

@dwnusbaum thank you for pointing out that glaring error 🤦
All is well now!

Copy link
Member

@dwnusbaum dwnusbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a quick comment to ConverterImpl:

// Note: XStream ignores readResolve and writeReplace methods on types with custom Converter implementations, so use marshal and unmarshal instead.

@car-roll car-roll changed the title check for null timings field Migrate from readResolve to unmarshal Apr 25, 2022
@car-roll car-roll enabled auto-merge (squash) April 25, 2022 23:19
@car-roll car-roll merged commit 39abe5c into jenkinsci:master Apr 25, 2022
@jglick
Copy link
Member

jglick commented Apr 26, 2022

@car-roll #528 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants