mojohaus / mojohaus/exec-maven-plugin
Java execution thread interrupted and not joined in vscode m2e build
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 191
- Forks
- 111
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
I have an exec-maven-plugin java execution that works well when run via the mvn CLI. But when run by vscode (where the plugin is called from the java language server via m2e), it doesn't run properly. A ClosedByInterruptException is triggered upon the first I/O operation. After some investigation I found that the execution thread is already interrupted before it enters my code.
AbstractExecJavaBase.java creates a bootstrapThread to run the exec class in. It then calls joinNonDaemonThreads to wait for that thread to finish. This assumes that the exec thread is not a daemon thread. But, threads inherit their daemon status from their parents, so if the plugin is run in a daemon thread, then the bootstrap thread will be a daemon thread. In that case it does not wait for the thread to finish and (when cleanupDaemonThreads is true) it immediately calls terminateThreads, interrupting the exec thread.
If the intention is for bootstrapThread (and its children) to be joined in joinNonDaemonThreads, then I think the code should explicitly call bootstrapThread.setDaemon(false).
Why is the plugin being run in a daemon thread? Well it seems that JDTLanguageServer in eclipse.jdt.ls uses CompletableFuture without an explicit executor for lots of build operations. These use ForkJoinPool.commonPool(), in which all threads are initialized as daemon threads.
cleanupDaemonThreads can be set to false to avoid the interrupt, or I can clear the interrupt flag in my code. But that's not a complete workaround, the plugin still won't wait for the thread to complete, and later build steps might run too soon.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in AbstractExecJavaBase.java, focusing on bootstrapThread, joinNonDaemonThreads, and terminateThreads, and trace how daemon status is inherited when the plugin runs through vscode/m2e. Reproduce the execution path with cleanupDaemonThreads enabled and verify that the Java execution is joined before cleanup interrupts it. Done means the execution and its children are allowed to finish without premature interruption.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100