From 1a8a00a82c3b05ec76f833deee073a0b1b2ac6fe Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Mon, 20 Apr 2015 20:58:48 -0700 Subject: [PATCH] If CLI main thread fails, kill the JVM no matter what. This prevents a long running CLI process (such as CloudBees OPE proccesses) to hang forever when the main thread fails. Whereas if the process terminates cleanly, the wrapper (such as systemd) can take corrective actions. --- cli/src/main/java/hudson/cli/CLI.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/src/main/java/hudson/cli/CLI.java b/cli/src/main/java/hudson/cli/CLI.java index fcabd3351e..6b6f37e414 100644 --- a/cli/src/main/java/hudson/cli/CLI.java +++ b/cli/src/main/java/hudson/cli/CLI.java @@ -384,7 +384,13 @@ public class CLI { // h.setLevel(ALL); // l.addHandler(h); // - System.exit(_main(_args)); + try { + System.exit(_main(_args)); + } catch (Throwable t) { + // if the CLI main thread die, make sure to kill the JVM. + t.printStackTrace(); + System.exit(-1); + } } public static int _main(String[] _args) throws Exception { -- GitLab