From b19b5a4d36ed5015eb59d621dab13e9742408805 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 25 Feb 2019 11:07:28 +0100 Subject: Reviewed exitCode handling Propagate server stop because of version change as exit code. --- main/client/src/MillClientMain.java | 17 ++++++++++++----- main/src/main/MillServerMain.scala | 10 +++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'main') diff --git a/main/client/src/MillClientMain.java b/main/client/src/MillClientMain.java index 3857caff..dc144f99 100644 --- a/main/client/src/MillClientMain.java +++ b/main/client/src/MillClientMain.java @@ -10,6 +10,12 @@ import java.nio.channels.FileChannel; import java.util.*; public class MillClientMain { + + // use methods instead of constants to avoid inlining by compiler + public static final int ExitClientCodeCannotReadFromExitCodeFile() { return 1; } + public static final int ExitServerCodeWhenIdle() { return 0; } + public static final int ExitServerCodeWhenVersionMismatch() { return 101; } + static void initServer(String lockBase, boolean setJnaNoSys) throws IOException,URISyntaxException{ String[] selfJars = System.getProperty("MILL_CLASSPATH").split(","); @@ -56,7 +62,8 @@ public class MillClientMain { System.setProperty("jna.nosys", "true"); } int index = 0; - while (index < 5) { + final int processLimit = 5; + while (index < processLimit) { index += 1; String lockBase = "out/mill-worker-" + index; new java.io.File(lockBase).mkdirs(); @@ -91,7 +98,7 @@ public class MillClientMain { } } - throw new Exception("Reached max process limit: " + 5); + throw new Exception("Reached max process limit: " + processLimit); } public static int run(String lockBase, @@ -151,10 +158,10 @@ public class MillClientMain { locks.serverLock.await(); - try(FileInputStream fos = new FileInputStream(lockBase + "/exitCode")){ - return Integer.parseInt(new BufferedReader(new InputStreamReader(fos)).readLine()); + try(FileInputStream fis = new FileInputStream(lockBase + "/exitCode")){ + return Integer.parseInt(new BufferedReader(new InputStreamReader(fis)).readLine()); } catch(Throwable e){ - return 1; + return ExitClientCodeCannotReadFromExitCodeFile(); } finally{ ioSocket.close(); } diff --git a/main/src/main/MillServerMain.scala b/main/src/main/MillServerMain.scala index 55cef632..862daaf7 100644 --- a/main/src/main/MillServerMain.scala +++ b/main/src/main/MillServerMain.scala @@ -37,9 +37,9 @@ object MillServerMain extends mill.main.MillServerMain[Evaluator.State]{ def handle(sig: Signal) = {} // do nothing }) new Server( - args0(0), + lockBase = args0(0), this, - () => System.exit(0), + () => System.exit(MillClientMain.ExitServerCodeWhenIdle()), 300000, mill.main.client.Locks.files(args0(0)) ).run() @@ -124,7 +124,11 @@ class Server[T](lockBase: String, if (clientMillVersion != serverMillVersion) { // FIXME: exiting with 0 isn't correct, see https://github.com/lihaoyi/mill/issues/557 stdout.println(s"Mill version changed ($serverMillVersion -> $clientMillVersion), re-starting server") - System.exit(0) + java.nio.file.Files.write( + java.nio.file.Paths.get(lockBase + "/exitCode"), + s"${MillClientMain.ExitServerCodeWhenVersionMismatch()}".getBytes() + ) + System.exit(MillClientMain.ExitServerCodeWhenVersionMismatch()) } val args = Util.parseArgs(argStream) val env = Util.parseMap(argStream) -- cgit v1.2.3