apache / maven-mvnd

Apache Maven Daemon
https://maven.apache.org/
Apache License 2.0
2.92k stars 212 forks source link

Hang with SpotBugs plugin and fork=false #979

Open rovarga opened 7 months ago

rovarga commented 7 months ago

A parallel build invoking spotbugs-maven-plugin without forking ends up hanging build sometimes. A thread dump shows two build tasks attempting to lock a monitor:

"BuilderThread 3" #52 [174264] prio=5 os_prio=0 cpu=4139,05ms elapsed=2286,53s tid=0x00007fd300a2ab80 nid=174264 waiting for monitor entry  [0x00007fd4361fb000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at org.apache.tools.ant.taskdefs.Redirector.complete(Redirector.java:971)
    - waiting to lock <0x0000000433800000> (a java.lang.Object)
    at org.apache.tools.ant.taskdefs.Java.run(Java.java:893)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:232)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:136)
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:109)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
    at java.lang.invoke.LambdaForm$DMH/0x00007fd3e01fc000.invokeVirtual(java.base@21.0.2/LambdaForm$DMH)
    at java.lang.invoke.LambdaForm$MH/0x00007fd3e1498c00.invoke(java.base@21.0.2/LambdaForm$MH)
    at java.lang.invoke.Invokers$Holder.invokeExact_MT(java.base@21.0.2/Invokers$Holder)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(java.base@21.0.2/DirectMethodHandleAccessor.java:153)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(java.base@21.0.2/DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke(java.base@21.0.2/Method.java:580)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at groovy.ant.AntBuilder.performTask(AntBuilder.java:347)
    at groovy.ant.AntBuilder.nodeCompleted(AntBuilder.java:286)
    at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:161)
    at groovy.ant.AntBuilder.doInvokeMethod(AntBuilder.java:219)
    at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:75)
    at org.codehaus.groovy.vmplugin.v8.IndyGuardsFiltersAndSignatures.invokeGroovyObjectInvoker(IndyGuardsFiltersAndSignatures.java:151)

and

"BuilderThread 11" #60 [174272] prio=5 os_prio=0 cpu=3370,14ms elapsed=2286,53s tid=0x00007fd300a3a340 nid=174272 waiting for monitor entry  [0x00007fd4359fb000]
   java.lang.Thread.State: BLOCKED (on object monitor)
    at org.apache.tools.ant.taskdefs.Redirector.complete(Redirector.java:971)
    - waiting to lock <0x0000000433828660> (a java.lang.Object)
    at org.apache.tools.ant.taskdefs.Java.run(Java.java:893)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:232)
    at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:136)
    at org.apache.tools.ant.taskdefs.Java.execute(Java.java:109)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
    at java.lang.invoke.LambdaForm$DMH/0x00007fd3e01fc000.invokeVirtual(java.base@21.0.2/LambdaForm$DMH)
    at java.lang.invoke.LambdaForm$MH/0x00007fd3e1498c00.invoke(java.base@21.0.2/LambdaForm$MH)
    at java.lang.invoke.Invokers$Holder.invokeExact_MT(java.base@21.0.2/Invokers$Holder)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invokeImpl(java.base@21.0.2/DirectMethodHandleAccessor.java:153)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(java.base@21.0.2/DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke(java.base@21.0.2/Method.java:580)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
    at groovy.ant.AntBuilder.performTask(AntBuilder.java:347)
    at groovy.ant.AntBuilder.nodeCompleted(AntBuilder.java:286)
    at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:161)
    at groovy.ant.AntBuilder.doInvokeMethod(AntBuilder.java:219)
    at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:75)
    at org.codehaus.groovy.vmplugin.v8.IndyGuardsFiltersAndSignatures.invokeGroovyObjectInvoker(IndyGuardsFiltersAndSignatures.java:151)

both objects mentioned are held in this context:

"In pipe (disconnected)" #109 [174409] daemon prio=5 os_prio=0 cpu=0,25ms elapsed=2277,97s tid=0x00007fd1f00059f0 nid=174409 in Object.wait()  [0x00007fd42bbfe000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait0(java.base@21.0.2/Native Method)
    - waiting on <0x00000007ff2284e0> (a java.util.LinkedList)
    at java.lang.Object.wait(java.base@21.0.2/Object.java:366)
    at java.lang.Object.wait(java.base@21.0.2/Object.java:339)
    at org.mvndaemon.mvnd.daemon.Server$DaemonInputStream.read(Server.java:714)
    - locked <0x00000007ff2284e0> (a java.util.LinkedList)
    at java.io.InputStream.read(java.base@21.0.2/InputStream.java:287)
    at java.io.FilterInputStream.read(java.base@21.0.2/FilterInputStream.java:119)
    at org.apache.tools.ant.taskdefs.Redirector.handleInput(Redirector.java:868)
    - locked <0x0000000433828660> (a java.lang.Object)
    at org.apache.tools.ant.taskdefs.Java.handleInput(Java.java:809)
    at org.apache.tools.ant.UnknownElement.handleInput(UnknownElement.java:240)
    at org.apache.tools.ant.Project.demuxInput(Project.java:1327)
    at org.apache.tools.ant.DemuxInputStream.read(DemuxInputStream.java:73)
    at java.io.FilterInputStream.read(java.base@21.0.2/FilterInputStream.java:119)
    at org.apache.tools.ant.taskdefs.Redirector.handleInput(Redirector.java:868)
    - locked <0x0000000433800000> (a java.lang.Object)
    at org.apache.tools.ant.taskdefs.Java.handleInput(Java.java:809)
    at org.apache.tools.ant.UnknownElement.handleInput(UnknownElement.java:240)
    at org.apache.tools.ant.Project.demuxInput(Project.java:1327)
    at org.apache.tools.ant.DemuxInputStream.read(DemuxInputStream.java:73)
    at java.io.InputStream.read(java.base@21.0.2/InputStream.java:220)
    at org.ops4j.io.Pipe$Pump.run(Pipe.java:141)

This does not happen when SpotBugs is using forked mode, i.e. runs in a different JVM.

rovarga commented 7 months ago

I guess DaemonInputStream is waiting for something to come from https://github.com/apache/maven-mvnd/blame/master/common/src/main/java/org/mvndaemon/mvnd/common/logging/TerminalOutput.java#L501, which never arrives.

rovarga commented 7 months ago

full jstack output: spotbugs_deadlock.txt