Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit 5c5eb4e

Browse files
jkeljofacebook-github-bot
authored andcommitted
Fix one cause of zombie buckd processes
Summary: We've gotten reports of multiple `buckd` processes being created for a single root, and `buck kill` doesn't make the extras go away. I've been investigating the prevalence of this problem, and along the way I found one cause of it. The comment in the code says the rest. Reviewed By: styurin fbshipit-source-id: 4a13247d7d
1 parent a3d1413 commit 5c5eb4e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/com/facebook/buck/cli/Main.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -2277,13 +2277,26 @@ public static void main(String[] args) {
22772277
if (socketPath.startsWith("local:")) {
22782278
socketPath = socketPath.substring("local:".length());
22792279
}
2280+
SecurityManager securityManager = System.getSecurityManager();
22802281
NGServer server =
22812282
new NGServer(
22822283
new NGListeningAddress(socketPath),
22832284
1, // store only 1 NGSession in a pool to avoid excessive memory usage
22842285
heartbeatTimeout);
22852286
daemonKillers = new DaemonKillers(housekeepingExecutorService, server, Paths.get(socketPath));
2286-
server.run();
2287+
try {
2288+
server.run();
2289+
} catch (RuntimeException e) {
2290+
// server.run() might throw (for example, if this process loses the race with another
2291+
// process to become the daemon for a given Buck root). Letting the exception go would
2292+
// kill this thread, but other non-daemon threads have already been started and we haven't
2293+
// yet installed the unhandled exception handler that would call System.exit, so this
2294+
// process would live forever as a zombie. We catch the exception, re-instate the original
2295+
// security manager (because NailGun has replaced it with one that blocks System.exit, and
2296+
// doesn't restore the original if an exception occurs), and exit.
2297+
System.setSecurityManager(securityManager);
2298+
LOG.error(e, "Exception thrown in NailGun server.");
2299+
}
22872300
System.exit(0);
22882301
}
22892302

0 commit comments

Comments
 (0)