Skip to content

fix(maven): synchronize batch runner invoke() to prevent concurrent access#34600

Merged
FrozenPandaz merged 1 commit intomasterfrom
fix/maven-batch-synchronized-invoke
Feb 27, 2026
Merged

fix(maven): synchronize batch runner invoke() to prevent concurrent access#34600
FrozenPandaz merged 1 commit intomasterfrom
fix/maven-batch-synchronized-invoke

Conversation

@MaxKless
Copy link
Collaborator

@MaxKless MaxKless commented Feb 25, 2026

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.

@MaxKless MaxKless requested review from a team, FrozenPandaz, lourw and vsavkin as code owners February 25, 2026 14:25
@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 455e590
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69a01d0b5d433e0008c4a309
😎 Deploy Preview https://deploy-preview-34600--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 455e590
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69a01d0b4e6c780008912fdd
😎 Deploy Preview https://deploy-preview-34600--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Feb 25, 2026

View your CI Pipeline Execution ↗ for commit 455e590

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 12m 47s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 16s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-26 10:31:27 UTC

@MaxKless MaxKless force-pushed the fix/maven-batch-synchronized-invoke branch from f5d87b7 to 75719ae Compare February 25, 2026 16:11
@MaxKless MaxKless requested a review from a team as a code owner February 25, 2026 16:11
@MaxKless MaxKless force-pushed the fix/maven-batch-synchronized-invoke branch from 75719ae to ce0663b Compare February 25, 2026 16:12
…access

Maven 4's ResidentMavenInvoker (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. The batch runner's
parallel thread pool can call invoke() from multiple threads
simultaneously when tasks are independent roots in the task graph,
which can cause deadlocks in Maven's internal session machinery.

Add @synchronized to both Maven 3 and Maven 4 adapter invoke() methods
to serialize Maven executions through the shared invoker instance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MaxKless MaxKless force-pushed the fix/maven-batch-synchronized-invoke branch from 2b42b9e to 455e590 Compare February 26, 2026 10:14
@github-actions
Copy link
Contributor

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx create-nx-workspace@22.6.0-pr.34600.455e590 my-workspace

Or just copy this version and use it in your own command:

22.6.0-pr.34600.455e590
Release details 📑
Published version 22.6.0-pr.34600.455e590
Triggered by @MaxKless
Branch fix/maven-batch-synchronized-invoke
Commit 455e590
Workflow run 22440052692

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@FrozenPandaz FrozenPandaz merged commit 53c0123 into master Feb 27, 2026
25 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/maven-batch-synchronized-invoke branch February 27, 2026 13:30
FrozenPandaz pushed a commit that referenced this pull request Mar 4, 2026
…ccess (#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 <noreply@anthropic.com>
(cherry picked from commit 53c0123)
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants