From 7d1942b615340a5adce603ebd8707e7bde1b71a6 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 12 Sep 2019 17:38:11 +0200 Subject: [PATCH] Port spawn factorio server deteached in client.js Sending ^C via the terminal on Linux may cause SIGINT to be sent twice to the factorio process, causing it to exit without completing the saving. This happens because the shell sends the interupt to all members of the process group for the job and this includes both the node client process and the factorio server process. Avoid this situation by passing detached to spawn when the platform is Linux, which causes the process to be created with its own process group and therefore not targeted by a SIGINT from the shell. This unfortunately does not work on Windows as we can't send SIGINT or ^C to a process there. Doing subprocces.kill on Windows terminates the process similarly to how SIGKILL works on Linux. This is a port of 6b090cd. --- CHANGELOG.md | 3 +++ client.js | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c787f92..a48e67e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,10 @@ Version 1.2.1 - Updated node-factorio-api to v0.3.8 to fix mod downloads randomly breaking ([#229][#229].) +- Fixed SIGINT being sent twice to Factorio server when interrupted by CTRL+C + on Linux ([#217][#217].) +[#217]: https://github.com/clusterio/factorioClusterio/issues/217 [#229]: https://github.com/clusterio/factorioClusterio/issues/229 ### Breaking Changes diff --git a/client.js b/client.js index 4de02024..f4318ae4 100644 --- a/client.js +++ b/client.js @@ -395,7 +395,8 @@ write-data=${ instance.path() }\r\n '--rcon-port', Number(process.env.RCONPORT) || instconf.clientPort, '--rcon-password', instconf.clientPassword, ], { - 'stdio': ['pipe', 'pipe', 'pipe'] + 'stdio': ['pipe', 'pipe', 'pipe'], + 'detached': process.platform === "linux", } ); factorio.stdout.on("data", data => { @@ -504,7 +505,8 @@ write-data=${ instance.path() }\r\n '--server-settings', instance.path("server-settings.json"), '--port', args.port || Number(process.env.FACTORIOPORT) || instanceconfig.factorioPort ], { - 'stdio': ['pipe', 'pipe', 'pipe'] + 'stdio': ['pipe', 'pipe', 'pipe'], + 'detached': process.platform === "linux", } );