sdedic commented on a change in pull request #2986:
URL: https://github.com/apache/netbeans/pull/2986#discussion_r645327408



##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/ui/AbstractLspInputOutputProvider.java
##########
@@ -145,7 +144,14 @@ public final void setIODescription(LspIO io, String 
description) {
             this.err = new PrintWriter(new LspWriter(false));
             Reader in;
             try {
-                in = new InputStreamReader(ioCtx.getStdIn(), "UTF-8");
+                in = new InputStreamReader(ioCtx.getStdIn(), "UTF-8") {
+                    @Override
+                    public void close() throws IOException {
+                        // the underlying StreamDecoder would just block on 
synchronized read(); close the underlying stream.
+                        ioCtx.getStdIn().close();

Review comment:
       Without this explicit close, the following lockup occurs when LSP client 
initiates the process:
   ```
   "pool-2-thread-1" #52 prio=5 os_prio=0 cpu=151.58ms 
   elapsed=22.34s tid=0x00007f3b388b3000 nid=0x43c3 waiting for monitor entry  
[0x00007f3b5d1bb000]
      java.lang.Thread.State: BLOCKED (on object monitor)
           at 
sun.nio.cs.StreamDecoder.close([email protected]/StreamDecoder.java:191)
           - waiting to lock <0x000000061a4d2068> (a 
org.netbeans.modules.java.lsp.server.ui.AbstractLspInputOutputProvider$LspIO$1)
           at 
java.io.InputStreamReader.close([email protected]/InputStreamReader.java:200)
           at 
org.netbeans.modules.java.lsp.server.ui.AbstractLspInputOutputProvider$LspIO$1.close(AbstractLspInputOutputProvider.java:152)
           at 
org.openide.util.io.ReaderInputStream.close(ReaderInputStream.java:130)
           at 
org.netbeans.modules.gradle.execute.GradleDaemonExecutor.closeInOutErr(GradleDaemonExecutor.java:348)
           - locked <0x000000061a4c7440> (a 
org.netbeans.modules.gradle.execute.GradleDaemonExecutor)
           at 
org.netbeans.modules.gradle.execute.GradleDaemonExecutor.cancel(GradleDaemonExecutor.java:368)
           at 
org.netbeans.modules.progress.spi.InternalHandle.requestCancel(InternalHandle.java:364)
           at 
org.netbeans.modules.java.lsp.server.progress.LspInternalHandle.forceRequestCancel(LspInternalHandle.java:93)
           at 
org.netbeans.modules.java.lsp.server.debugging.DebugAdapterContext.requestProcessTermination(DebugAdapterContext.java:140)
           at 
org.netbeans.modules.java.lsp.server.debugging.launch.NbDisconnectRequestHandler.destroyDebugSession(NbDisconnectRequestHandler.java:49)
           at 
org.netbeans.modules.java.lsp.server.debugging.launch.NbDisconnectRequestHandler.disconnect(NbDisconnectRequestHandler.java:35)
           at 
org.netbeans.modules.java.lsp.server.debugging.NbProtocolServer.disconnect(NbProtocolServer.java:180)
           at 
jdk.internal.reflect.NativeMethodAccessorImpl.invoke0([email protected]/Native 
Method)
           at 
jdk.internal.reflect.NativeMethodAccessorImpl.invoke([email protected]/NativeMethodAccessorImpl.java:62)
           at 
jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke([email protected]/DelegatingMethodAccessorImpl.java:43)
           at java.lang.reflect.Method.invoke([email protected]/Method.java:566)
           at 
org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:65)
   
           at 
org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint$$Lambda$213/0x0000000800468440.apply(Unknown
 Source)
           at 
org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.request(GenericEndpoint.java:120)
           at 
org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleRequest(RemoteEndpoint.java:261)
           at 
org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:190)
           at 
org.netbeans.modules.java.lsp.server.debugging.Debugger$ConsumeWithLookup.lambda$consume$0(Debugger.java:92)
           at 
org.netbeans.modules.java.lsp.server.debugging.Debugger$ConsumeWithLookup$$Lambda$771/0x0000000800aa7c40.run(Unknown
 Source)
           at 
org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:45)
           at org.openide.util.lookup.Lookups.executeWith(Lookups.java:278)
           at 
org.netbeans.modules.java.lsp.server.debugging.Debugger$ConsumeWithLookup.consume(Debugger.java:90)
           at 
org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:194)
           at 
org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:94)
           at 
org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:113)
           at 
java.util.concurrent.Executors$RunnableAdapter.call([email protected]/Executors.java:515)
           at 
java.util.concurrent.FutureTask.run([email protected]/FutureTask.java:264)
           at 
java.util.concurrent.ThreadPoolExecutor.runWorker([email protected]/ThreadPoolExecutor.java:1128)
           at 
java.util.concurrent.ThreadPoolExecutor$Worker.run([email protected]/ThreadPoolExecutor.java:628)
           at java.lang.Thread.run([email protected]/Thread.java:834)
   ....
   "DisconnectableInputStream source reader" #63 daemon prio=5 os_prio=0 
cpu=1.19ms elapsed=20.00s tid=0x00007f3a796c2800 nid=0x43f2 in Object.wait()  
[0x00007f3a993e7000]
      java.lang.Thread.State: TIMED_WAITING (on object monitor)
           at java.lang.Object.wait([email protected]/Native Method)
           - waiting on <no object reference available>
           at 
java.io.PipedInputStream.read([email protected]/PipedInputStream.java:326)
           - waiting to re-lock in wait() <0x000000061a485ed8> (a 
org.netbeans.modules.java.lsp.server.debugging.launch.NbProcessConsole$1)
           at 
java.io.PipedInputStream.read([email protected]/PipedInputStream.java:377)
           - waiting to re-lock in wait() <0x000000061a485ed8> (a 
org.netbeans.modules.java.lsp.server.debugging.launch.NbProcessConsole$1)
           at 
sun.nio.cs.StreamDecoder.readBytes([email protected]/StreamDecoder.java:284)
           at 
sun.nio.cs.StreamDecoder.implRead([email protected]/StreamDecoder.java:326)
           at 
sun.nio.cs.StreamDecoder.read([email protected]/StreamDecoder.java:178)
           - locked <0x000000061a4d2068> (a 
org.netbeans.modules.java.lsp.server.ui.AbstractLspInputOutputProvider$LspIO$1)
           at 
sun.nio.cs.StreamDecoder.read0([email protected]/StreamDecoder.java:127)
           - locked <0x000000061a4d2068> (a 
org.netbeans.modules.java.lsp.server.ui.AbstractLspInputOutputProvider$LspIO$1)
           at 
sun.nio.cs.StreamDecoder.read([email protected]/StreamDecoder.java:112)
           at 
java.io.InputStreamReader.read([email protected]/InputStreamReader.java:168)
           at 
org.openide.util.io.ReaderInputStream.read(ReaderInputStream.java:65)
           at 
org.openide.util.io.ReaderInputStream.read(ReaderInputStream.java:88)
           at 
org.gradle.util.DisconnectableInputStream$1.run(DisconnectableInputStream.java:98)
           at java.lang.Thread.run([email protected]/Thread.java:834)
   ```
   Because of 
[NETBEANS-2038](https://issues.apache.org/jira/browse/NETBEANS-2038), streams 
are closed **before**  Gradle is instructed to stop the build. It could be 
possible to flag + filter the streams in Gradle, or close input stream 
**after** instructing Gradle to stop.
   
   Full thread dump:
   
[threaddump-streamdecoder.txt](https://github.com/apache/netbeans/files/6596263/threaddump-streamdecoder.txt)
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to