From 9f74d7b2ecbbd85473f8b5559c14b4556b221ec2 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sun, 22 Mar 2020 03:28:05 +0100 Subject: [PATCH] Fix shutdown logic for slave Shutdown running instances and close the connection to the master server on slave stop. Remove call to process.exit on shutdown as it's no longer needed. --- client.js | 19 ++++++++++++------- test/integration/index.js | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client.js b/client.js index 3d21c2dd..a49cbddb 100644 --- a/client.js +++ b/client.js @@ -640,10 +640,10 @@ class Slave extends link.Link { } async stop() { - for (let instanceConnection of this.instanceConnections.values()) { - // XXX this neeeds more thought to it - // await instance.stop(); + for (let instanceId of this.instanceConnections.keys()) { + await this.stopInstance(instanceId); } + this.connector.close("shutdown"); } } @@ -841,10 +841,15 @@ async function startClient() { secondSigint = true; console.log("Caught interrupt signal, shutting down"); - slave.stop().then(() => { - // There's currently no shutdown mechanism for instance plugins so - // they keep the event loop alive. - process.exit(); + slave.stop().catch(err => { + console.error(` ++---------------------------------------------------------------+ +| Unexpected error occured while stopping slave, please report | +| it to https://github.com/clusterio/factorioClusterio/issues | ++---------------------------------------------------------------+` + ); + console.error(err); + process.exit(1); }); }); diff --git a/test/integration/index.js b/test/integration/index.js index 848a3b81..668a56b4 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -79,7 +79,7 @@ before(async function() { }); after(async function() { - this.timeout(200000); + this.timeout(20000); if (slaveProcess) { console.log("Shutting down slave"); slaveProcess.kill("SIGINT");