From ec22622d782f331f1afc364fca8300b1b31b9e49 Mon Sep 17 00:00:00 2001 From: seven Date: Sat, 15 Jul 2023 14:24:38 +0800 Subject: [PATCH] fix terminate issue --- src/engine.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine.ts b/src/engine.ts index d949ada..392c563 100644 --- a/src/engine.ts +++ b/src/engine.ts @@ -131,17 +131,20 @@ const cleanupIndices = async (): Promise => { const killProcess = async (): Promise => { try { - const closeEmit = new Promise((resolve) => server.on('close', () => resolve('close'))); + const closeEmit = new Promise((resolve, reject) => { + server.on('exit', (code, signal) => resolve(`exit: code:${code}, signal:${signal}`)); + server.on('error', (err) => reject(`error: ${err}`)); + }); - server.kill('SIGTERM', { forceKillAfterTimeout: 2000 }); + server.kill('SIGTERM', { forceKillAfterTimeout: 10000 }); const result = await Promise.race([ closeEmit, - new Promise((resolve) => setTimeout(() => resolve('timout'), 3000)), + new Promise((resolve) => setTimeout(() => resolve('timout'), 15000)), ]); debug(`close result: ${result}`); } catch (e) { - debug(`Could not stop ${engineOptions.engine}, killing system wide`); + debug(`Could not stop ${engineOptions.engine},error: ${e} killing system wide`); } };