From 70bd611ee9c901247663ff09eb87c9a84ba706d0 Mon Sep 17 00:00:00 2001 From: Michael Krens Date: Wed, 1 Jul 2020 02:39:42 +0200 Subject: [PATCH 1/9] spawn processes in detached mode to make a graceful shutdown on SIGINT possible --- src/emulator/downloadableEmulators.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/emulator/downloadableEmulators.ts b/src/emulator/downloadableEmulators.ts index 36f16ed40fa..494d7e6dc04 100644 --- a/src/emulator/downloadableEmulators.ts +++ b/src/emulator/downloadableEmulators.ts @@ -213,6 +213,11 @@ async function _runBinary( try { emulator.instance = childProcess.spawn(command.binary, command.args, { env: { ...process.env, ...extraEnv }, + // `detached` must be true as else a SIGINT (Ctrl-c) will stop the child process before we can handle a + // graceful shutdown and call `downloadableEmulators.stop(...)` ourselves. + // Note that it seems to be a problem with gRPC processes for which a fix may be found on the Java side + // related to this issue: https://github.com/grpc/grpc-java/pull/6512 + detached: true, stdio: ["inherit", "pipe", "pipe"], }); } catch (e) { From eb9bd3001e9563610c9676c6683e2e59a0d0008d Mon Sep 17 00:00:00 2001 From: Michael Krens Date: Wed, 1 Jul 2020 04:25:47 +0200 Subject: [PATCH 2/9] Adds --export-on-exit flag to automatically export emulator data on exit --- src/commands/emulators-exec.ts | 1 + src/commands/emulators-export.ts | 93 +-------------- src/commands/emulators-start.ts | 4 +- src/commands/ext-dev-emulators-exec.ts | 1 + src/commands/ext-dev-emulators-start.ts | 4 +- src/emulator/commandUtils.ts | 81 +++++++++++-- src/emulator/controller.ts | 147 ++++++++++++++++++++++-- src/emulator/pubsubEmulator.ts | 1 + src/test/emulators/commandUtils.spec.ts | 52 +++++++++ 9 files changed, 269 insertions(+), 115 deletions(-) create mode 100644 src/test/emulators/commandUtils.spec.ts diff --git a/src/commands/emulators-exec.ts b/src/commands/emulators-exec.ts index 4b9c9394e23..24509f2cd66 100644 --- a/src/commands/emulators-exec.ts +++ b/src/commands/emulators-exec.ts @@ -9,4 +9,5 @@ module.exports = new Command("emulators:exec