From 11938d3d3770f76e9f7017e049b47cf00d2d2d93 Mon Sep 17 00:00:00 2001 From: Huy Pham Date: Wed, 25 Mar 2020 14:03:00 -0700 Subject: [PATCH] fix: handle SIGINT in ErrorHandler Currently, when running the Functions Framework in a Docker container by running `docker run`, one cannot stop the running container with Ctrl+C. This is because the Functions Framework doesn't handle SIGINT in the ErrorHandler. This change handles SIGINT in the similar fashion as SIGTERM i.e. close the web server and exit the process. --- src/invoker.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/invoker.ts b/src/invoker.ts index 57c2479b..a37c76e5 100644 --- a/src/invoker.ts +++ b/src/invoker.ts @@ -535,9 +535,12 @@ export class ErrorHandler { logAndSendError(new Error(`Process exited with code ${code}`), latestRes); }); - process.on('SIGTERM', () => { - this.server.close(() => { - process.exit(); + ['SIGINT', 'SIGTERM'].forEach(signal => { + process.on(signal as NodeJS.Signals, () => { + console.log(`Received ${signal}`); + this.server.close(() => { + process.exit(); + }); }); }); }