Skip to content

Commit 53c0123

Browse files
MaxKlessclaude
andauthored
fix(maven): synchronize batch runner invoke() to prevent concurrent access (#34600)
## Current Behavior The Maven batch runner uses a parallel thread pool to execute tasks. When multiple tasks are independent roots in the task graph, they get picked up by separate threads simultaneously. Both threads call `invoke()` on the same shared `CachingResidentMavenInvoker` (Maven 4) or `CachingMaven3Invoker` (Maven 3) instance concurrently. Maven 4's `LookupInvoker.invoke()` is not thread-safe — it snapshots/restores `System.getProperties()` and the thread context classloader in a `finally` block, and all concurrent invocations share the same resident `MavenContext`. This can cause deadlocks in Maven's internal session machinery. ## Expected Behavior Maven executions through the shared invoker are serialized via `@Synchronized`, preventing concurrent access to non-thread-safe Maven internals. The parallel thread pool still handles task graph management, build state recording, and result emission concurrently. Co-authored-by: Claude Opus 4.6 <[email protected]>
1 parent 8255c28 commit 53c0123

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

packages/maven/batch-runner-adapters/maven3/src/main/kotlin/dev/nx/maven/adapter/maven3/CachingMaven3Invoker.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class CachingMaven3Invoker(
7171
log.debug("CachingMaven3Invoker initialized")
7272
}
7373

74+
@Synchronized
7475
override fun invoke(
7576
args: List<String>,
7677
workingDir: File,

packages/maven/batch-runner-adapters/maven4/src/main/kotlin/dev/nx/maven/adapter/maven4/Maven4AdapterInvoker.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Maven4AdapterInvoker(
4646
log.debug("Maven4AdapterInvoker ready")
4747
}
4848

49+
@Synchronized
4950
override fun invoke(
5051
args: List<String>,
5152
workingDir: File,

0 commit comments

Comments
 (0)