From 6d9749699da62a07ae933bd2c9a9ced8ccf877df Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Mon, 25 Apr 2022 14:26:46 +0200 Subject: [PATCH] refactor(AWS Local Invocation): Rely on observable spawn It's to better debug observed issues --- lib/plugins/aws/invoke-local/index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/plugins/aws/invoke-local/index.js b/lib/plugins/aws/invoke-local/index.js index 3afd8a62f..d7ad66116 100644 --- a/lib/plugins/aws/invoke-local/index.js +++ b/lib/plugins/aws/invoke-local/index.js @@ -605,28 +605,25 @@ class AwsInvokeLocal { const wrapperPath = await this.resolveRuntimeWrapperPath('invoke.py'); - return new Promise((resolve, reject) => { - const python = spawn(runtime.split('.')[0], ['-u', wrapperPath, handlerPath, handlerName], { - env: process.env, - }); + return new Promise((resolve) => { + const python = spawnExt( + runtime.split('.')[0], + ['-u', wrapperPath, handlerPath, handlerName], + { + env: process.env, + } + ); python.stdout.on('data', (buf) => { writeText(buf.toString()); }); python.stderr.on('data', (buf) => { writeText(buf.toString()); }); - python.on('close', () => resolve()); - let isRejected = false; - python.on('error', (error) => { - isRejected = true; - reject(error); - }); - process.nextTick(() => { - if (isRejected) return; // Runtime not available - python.stdin.write(input); - python.stdin.end(); - }); + python.child.stdin.write(input); + python.child.stdin.end(); + + resolve(python); }); }