From 6cd2f0f7d88170b7c4a37a17c132cfa8f664f9a2 Mon Sep 17 00:00:00 2001 From: Zhihe Li Date: Fri, 23 Aug 2024 15:21:34 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Fix=20windows=20hanging?= =?UTF-8?q?=20when=20client=20agent=20isn't=20running=20(#2459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electron-app/src/helpers/spawn-promise.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ui/desktop/electron-app/src/helpers/spawn-promise.js b/ui/desktop/electron-app/src/helpers/spawn-promise.js index 8835509e0..e057c0498 100644 --- a/ui/desktop/electron-app/src/helpers/spawn-promise.js +++ b/ui/desktop/electron-app/src/helpers/spawn-promise.js @@ -90,9 +90,9 @@ module.exports = { }, }); - const { stdout, stderr } = childProcess; + const { stdout, stderr, error } = childProcess; - return { stdout: stdout?.toString(), stderr: stderr?.toString() }; + return { stdout: stdout?.toString(), stderr: stderr?.toString(), error }; }, /** @@ -111,6 +111,19 @@ module.exports = { resolve({ childProcess, stderr: data.toString() }); }); childProcess.on('error', (err) => reject(err)); + + // In case the process has no stdio and didn't error out, resolve a + // promise once the child process closes so we're not waiting forever. + // Windows doesn't seem to return any error nor any output from stderr when + // a timeout occurs so this guarantees we return a response to the caller. + // Otherwise this should not get hit as we should be returning a response + // from one of the handlers above. + childProcess.on('close', () => + resolve({ + childProcess, + stderr: JSON.stringify({ error: 'Process was closed.' }), + }), + ); }); }, };