fix: rearrange exit hook to try to fix closing

This commit is contained in:
Eli Bosley
2024-01-03 15:12:17 -05:00
parent 33c69bf76f
commit f91ae5c7a0

View File

@@ -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);