From ff9d0b58b3b6866ccd54c4c54a457b74c051d603 Mon Sep 17 00:00:00 2001 From: Julian Grinblat Date: Fri, 22 Jul 2022 08:29:03 +0900 Subject: [PATCH] fix: Cleanly exit node process (#1508) --- src/events/http/HttpServer.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/events/http/HttpServer.js b/src/events/http/HttpServer.js index f22f63ce6..15a62f8d6 100644 --- a/src/events/http/HttpServer.js +++ b/src/events/http/HttpServer.js @@ -201,18 +201,13 @@ export default class HttpServer { log.notice() log.notice('Enter "rp" to replay the last request') - process.openStdin().addListener('data', (data) => { - // note: data is an object, and when converted to a string it will - // end with a linefeed. so we (rather crudely) account for that - // with toString() and then trim() - if (data.toString().trim() === 'rp') { - this.#injectLastRequest() - } - }) + process.stdin.addListener('data', this.#handleStdin) } // stops the server stop(timeout) { + process.stdin.removeListener('data', this.#handleStdin) + process.stdin.pause() return this.#server.stop({ timeout, }) @@ -226,6 +221,15 @@ export default class HttpServer { } } + #handleStdin = (data) => { + // note: data is an object, and when converted to a string it will + // end with a linefeed. so we (rather crudely) account for that + // with toString() and then trim() + if (data.toString().trim() === 'rp') { + this.#injectLastRequest() + } + } + #logPluginIssue() { log.notice( 'If you think this is an issue with the plugin please submit it, thanks!\nhttps://github.com/dherault/serverless-offline/issues',