Skip to content

Commit fda7c7a

Browse files
committed
feat: swap to async exit hook
1 parent cb62ba4 commit fda7c7a

File tree

2 files changed

+13
-29
lines changed

2 files changed

+13
-29
lines changed

api/src/index.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import https from 'https';
99

1010
import type { RawServerDefault } from 'fastify';
1111
import CacheableLookup from 'cacheable-lookup';
12-
import exitHook from 'exit-hook';
12+
import { asyncExitHook, gracefulExit } from 'exit-hook';
1313
import { WebSocket } from 'ws';
1414

1515
import { logger } from '@app/core/log';
@@ -91,17 +91,19 @@ try {
9191
// Start webserver
9292
server = await bootstrapNestServer();
9393

94-
// On process exit stop HTTP server
95-
exitHook(async (signal) => {
96-
console.log('exithook', signal);
97-
await server?.close?.();
98-
// If port is unix socket, delete socket before exiting
99-
unlinkUnixPort();
94+
asyncExitHook(
95+
async (signal) => {
96+
console.log('exithook', signal);
97+
await server?.close?.();
98+
// If port is unix socket, delete socket before exiting
99+
unlinkUnixPort();
100100

101-
shutdownApiEvent();
101+
shutdownApiEvent();
102102

103-
process.exit(0);
104-
});
103+
gracefulExit();
104+
},
105+
{ wait: 9999 }
106+
);
105107
// Start a loop to run the app
106108
await new Promise(() => {});
107109
} catch (error: unknown) {
@@ -115,5 +117,5 @@ try {
115117
}
116118
shutdownApiEvent();
117119
// Kill application
118-
process.exit(1);
120+
gracefulExit(1);
119121
}

api/src/unraid-api/cli/report.spec.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)