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 23, 2019
1 parent 5bba23d commit 7d5bd0b
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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 +107,28 @@ 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) {
try {
if (process.getInputStream() != null) {
process.getInputStream().close();
}
} catch (IOException e) {
}
try {
if (process.getOutputStream() != null) {
process.getOutputStream().close();
}
} catch (IOException e) {
}
try {
if (process.getErrorStream() != null) {
process.getErrorStream().close();
}
} catch (IOException e) {
}
}
System.gc();
}
}
Expand Down

0 comments on commit 7d5bd0b

Please sign in to comment.