Fix ConcurrentModificationException in parallel builds#284
Closed
wisechengyi wants to merge 1 commit intonebula-plugins:mainfrom
Closed
Fix ConcurrentModificationException in parallel builds#284wisechengyi wants to merge 1 commit intonebula-plugins:mainfrom
wisechengyi wants to merge 1 commit intonebula-plugins:mainfrom
Conversation
Collaborator
Author
|
Close in favor of #285 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix ConcurrentModificationException in parallel builds
Problem
When running Gradle commands with parallel execution enabled (or even single commands like
./gradlew help), the build fails with aConcurrentModificationException:This issue occurs even when
saveGlobalLockis not scheduled to run, affecting basic Gradle operations. The problem is particularly severe with Gradle 9.0 due to stricter concurrency enforcement.Root Cause
The issue stems from lazy task realization being triggered during parallel task execution:
Configuration Phase: Tasks are registered lazily using
tasks.register(), but their properties aren't fully evaluated until accessed.Execution Phase: When subproject
saveLocktasks execute, theirdoFirstactions perform validation checks:Lazy Realization Trigger: Accessing
globalSave.outputLocktriggers evaluation of the task's convention mappings, which contains this problematic code:Concurrent Modification: When multiple subproject tasks run in parallel, they all:
saveGlobalLocktaskConcurrentModificationExceptionThe same issue exists in reverse:
saveGlobalLocklooks up subproject tasks during execution, causing similar problems.Solution
Replace runtime task lookups with direct file system checks to avoid triggering lazy task realization:
In
configureSaveTask(DependencyLockTaskConfigurer.groovy:157-167)Before:
After:
In
configureGlobalSaveTask(DependencyLockTaskConfigurer.groovy:195-207)Before:
After:
Benefits
DeprecationLogger.whileDisabledusageThe fix ensures that validation checks directly inspect the file system rather than accessing task objects, preventing race conditions in parallel builds.