Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File handle leak on Win with Java 11(.0.2) #303

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};
}
}
}