Skip to content

Commit

Permalink
fix terminate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Blankll committed Jul 15, 2023
1 parent 2955215 commit ec22622
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ const cleanupIndices = async (): Promise<void> => {

const killProcess = async (): Promise<void> => {
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`);
}
};

Expand Down

0 comments on commit ec22622

Please sign in to comment.