On Thu, 20 Aug 2026 13:28:37 GMT, Dušan Bálek <[email protected]> wrote:

> Running two or more `jlink` invocations concurrently in the same JVM through 
> the `ToolProvider` API causes the simultaneous `run` calls to interfere with 
> one another, even when each invocation targets a distinct `--output` 
> directory and the invocations share no inputs. They may fail with errors such 
> as:
> 
> Error: java.lang.IllegalStateException: stream has already been operated upon 
> or closed
> Error: Resource XYZ already present
> 
> The problem is that Main.run(...) correctly creates a new `JlinkTask` for 
> each call, but `JlinkTask` defeats this isolation by sharing static 
> `TaskHelper` and `OptionsHelper` instances. Concurrent invocations can 
> therefore overwrite one another’s parsed options and plugin pipelines.
> 
> The proposed solution is to make `taskHelper` and `optionsHelper` instance 
> fields of `JlinkTask`. This preserves actual concurrency. Synchronizing the 
> provider would unnecessarily serialize image creation and would not protect 
> separate provider instances or direct calls to `Main.run(...)`.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Marked as reviewed by alanb (Reviewer).

test/jdk/tools/jlink/JLinkToolProviderTest.java line 71:

> 69:                 readyLatch.await();
> 70:             } finally {
> 71:                 startLatch.countDown();

FYI, instead of two latches, you could just use a Phaser and use 
arriveAndAwaitAdvance to have each task attempt the jlink command at around the 
same time.

test/jdk/tools/jlink/JLinkToolProviderTest.java line 86:

> 84:         checkJlinkOptions("--help");
> 85:         checkJlinkOptions("--list-plugins");
> 86:         checkConcurrentAccess(3);

Future maintainers we will wonder why "3" was picked, maybe 
Runtime::availableProcessors / 4 would be better.

-------------

PR Review: https://git.openjdk.org/jdk/pull/32469#pullrequestreview-4984199509
PR Review Comment: https://git.openjdk.org/jdk/pull/32469#discussion_r3822752250
PR Review Comment: https://git.openjdk.org/jdk/pull/32469#discussion_r3822767367

Reply via email to