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 authored and fbricon committed Feb 25, 2019
1 parent 5bba23d commit 458d491
Showing 1 changed file with 15 additions and 2 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 All @@ -37,7 +40,7 @@ public final class ParentProcessWatcher implements Runnable, Function<MessageCon
private static final boolean isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;

private static final long INACTIVITY_DELAY_SECS = 30 *1000;
private static final int POLL_DELAY_SECS = 2;
private static final int POLL_DELAY_SECS = 10;
private volatile long lastActivityTime;
private final ProcessLanguageServer server;
private ScheduledFuture<?> task;
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 All @@ -121,4 +134,4 @@ public MessageConsumer apply(final MessageConsumer consumer) {
consumer.consume(message);
};
}
}
}

0 comments on commit 458d491

Please sign in to comment.