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

Use lists instead of arrays for FlowNode actions to make deserialization more robust #263

Merged
merged 6 commits into from
May 1, 2024

Conversation

dwnusbaum
Copy link
Member

@dwnusbaum dwnusbaum commented Apr 29, 2024

I did not realize this, but if you try to deserialize a Pipeline that has a FlowNode with an action from a plugin that is disabled or no longer installed, the FlowNode itself will fail to be deserialized, leaving the flow graph corrupted. It seems like it would be preferential to have RobustCollectionConverter work for FlowNode actions, so that only the problematic action itself fails to be deserialized, but the FlowNode itself and all other actions are preserved.

The reason for the current behavior is that right now, the fields used to serialize FlowNode actions are arrays, and core's RobustCollectionConverter has no equivalent for arrays (fair enough I guess).

I created some tests to demonstrate the original behavior, but then I realized that the serial format of lists and arrays as far as XStream is concerned actually seems to be interchangeable (maybe not true in general?), so I figured I might as well file a patch instead of just tests. Besides potential concerns with backwards compatibility, I am not sure if there is any specific reason that arrays were used originally. Maybe to reduce memory usage or something like that?

For now I'm just filing as a draft because I'm not sure if this is safe or if there were any particular reasons we were using arrays previously.

Testing done

Only tested briefly against this plugin using the new and existing automated tests.

Submitter checklist

Preview Give feedback

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably various files here could be deleted, and in general I prefer to use zip files to avoid cluttering GitHub search results, but for now at least having the bare files as test resources makes it easy to see what is being tested.

Comment on lines 86 to 90
var b = p.getLastBuild();
var stageBodyStartNode = (StepStartNode) b.getExecution().getNode("4");
assertThat(stageBodyStartNode, not(nullValue()));
var label = stageBodyStartNode.getPersistentAction(LabelAction.class);
assertThat(label.getDisplayName(), equalTo("test"));
Copy link
Member Author

Choose a reason for hiding this comment

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

Without the patch, the whole Pipeline itself fails to load because the active head refers to a node with the action from the class that is no longer present.

Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

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

Test is failing on Windows, but otherwise seems like a good idea.

@dwnusbaum dwnusbaum marked this pull request as ready for review April 30, 2024 21:44
@dwnusbaum dwnusbaum requested a review from a team as a code owner April 30, 2024 21:44
@jglick jglick merged commit 6713aed into jenkinsci:master May 1, 2024
14 checks passed
@dwnusbaum dwnusbaum deleted the robust-action-deserialization branch May 1, 2024 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants