Skip to content

Commit

Permalink
File handle leak on Win with Java 11(.0.2)
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed Feb 24, 2019
1 parent 5bba23d commit 08a8350
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.services.LanguageServer;

import com.google.common.io.Closeables;

/**
* Watches the parent process PID and invokes exit if it is no longer available.
* This implementation waits for periods of inactivity to start querying the PIDs.
*/
public final class ParentProcessWatcher implements Runnable, Function<MessageConsumer, MessageConsumer>{

private static final Logger LOGGER = Logger.getLogger(ParentProcessWatcher.class.getName());
private static final boolean isJava1x = System.getProperty("java.version").startsWith("1.");

/**
* Exit code returned when XML Language Server is forced to exit.
Expand Down Expand Up @@ -106,6 +109,16 @@ private boolean parentProcessStillRunning() {
// On Windows, when the Java LS is idle, we need to explicitly request a GC,
// to prevent an accumulation of zombie processes, as finalize() will be called.
if (isWindows) {
// Java >= 9 doesn't close the handle when the process is garbage collected
// We need to close the opened streams
if (!isJava1x) {
Closeables.closeQuietly(process.getInputStream());
Closeables.closeQuietly(process.getErrorStream());
try {
Closeables.close(process.getOutputStream(), false);
} catch (IOException e) {
}
}
System.gc();
}
}
Expand Down

0 comments on commit 08a8350

Please sign in to comment.