[JENKINS-48974] Use NIO Ivy file lock strategy #148
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
See JENKINS-72050. Ivy 2.5.2 (a security release) introduced flakiness in
@Grab
relating to XML parsing. After upgrading to 2.5.3, this regression was apparently resolved, but a user has still noticed that@Grab
is still flaky.Problem
See JENKINS-72050 (comment). Building 14 Pipeline jobs in parallel, each of which uses
@Grab
, results in failures. These failures are not present when running the jobs sequentially.Evaluation
See IVY-654 (comment). As described by @danielcwc, the default Ivy cache has no lock protection. From https://ant.apache.org/ivy/history/2.5.3/concept.html#cache:
From https://ant.apache.org/ivy/history/2.5.3/settings/caches.html:
From https://ant.apache.org/ivy/history/2.5.3/settings/lock-strategies.html:
From this we can see that the bug is a classic race condition.
Solution
Use a file locking strategy, such as
or
Implementation
A proper implementation would be to add
<caches lockStrategy="artifact-lock-nio" />
below https://github.com/apache/groovy/blob/de5ff81e020b25289c2eba8f245d46118e3c799f/src/resources/groovy/grape/defaultGrapeConfig.xml#L22 in Groovy'sdefaultGrapeConfig.xml
. However, this would involve making a change to Groovy upstream, waiting for that to be released, and then upgrading to that release, a nontrivial endeavor.Instead, we change the lock strategy in
GrapeHack
(introduced in jenkinsci/workflow-cps-global-lib-plugin#9) from its default ofno-lock
toartifact-lock-nio
, offering an escape hatch in case the user has any problems. This works around the upstream Groovy issue without requiring us to patch and release a new version of Groovy.Testing done
Ran the test described in the linked issue comment. Reproduced the failure when running 14 parallel jobs before this PR. Could no longer reproduce the failure after this PR.
Verified in the debugger and by viewing
FINE
-level logs that the workaround was executing as expected, that the lock strategy wasno-lock
beforeGrapeHack
executed, and that the lock strategy wasartifact-lock-nio
afterGrapeHack
executed.Submitter checklist