From f91ae5c7a035b3989620d94ea01b92d00c509f04 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Wed, 3 Jan 2024 15:12:17 -0500 Subject: [PATCH] fix: rearrange exit hook to try to fix closing --- api/src/index.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/api/src/index.ts b/api/src/index.ts index 9863614bd..aa966fca8 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -38,15 +38,6 @@ const unlinkUnixPort = () => { // Boot app void am( async () => { - exitHook(() => { - server?.close?.(); - // If port is unix socket, delete socket before exiting - unlinkUnixPort(); - - shutdownApiEvent(); - - process.exit(0); - }); environment.IS_MAIN_PROCESS = true; logger.debug('ENV %o', env); @@ -103,7 +94,15 @@ void am( await validateApiKeyIfPresent(); // On process exit stop HTTP server - this says it supports async but it doesnt seem to - + exitHook(() => { + server?.close?.(); + // If port is unix socket, delete socket before exiting + unlinkUnixPort(); + + shutdownApiEvent(); + + process.exit(0); + }); }, async (error: NodeJS.ErrnoException) => { logger.error('API-GLOBAL-ERROR %s %s', error.message, error.stack);