From c7d4e39287c10609993d62bf62f5b2a4fca5b759 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Wed, 29 Jan 2025 11:47:30 -0500 Subject: [PATCH] feat: swap to async exit hook --- api/src/index.ts | 24 +++++++++++++----------- api/src/unraid-api/cli/report.spec.ts | 18 ------------------ 2 files changed, 13 insertions(+), 29 deletions(-) delete mode 100644 api/src/unraid-api/cli/report.spec.ts diff --git a/api/src/index.ts b/api/src/index.ts index 387505925..841a7b90c 100644 --- a/api/src/index.ts +++ b/api/src/index.ts @@ -9,7 +9,7 @@ import https from 'https'; import type { RawServerDefault } from 'fastify'; import CacheableLookup from 'cacheable-lookup'; -import exitHook from 'exit-hook'; +import { asyncExitHook, gracefulExit } from 'exit-hook'; import { WebSocket } from 'ws'; import { logger } from '@app/core/log'; @@ -91,17 +91,19 @@ try { // Start webserver server = await bootstrapNestServer(); - // On process exit stop HTTP server - exitHook(async (signal) => { - console.log('exithook', signal); - await server?.close?.(); - // If port is unix socket, delete socket before exiting - unlinkUnixPort(); + asyncExitHook( + async (signal) => { + console.log('exithook', signal); + await server?.close?.(); + // If port is unix socket, delete socket before exiting + unlinkUnixPort(); - shutdownApiEvent(); + shutdownApiEvent(); - process.exit(0); - }); + gracefulExit(); + }, + { wait: 9999 } + ); // Start a loop to run the app await new Promise(() => {}); } catch (error: unknown) { @@ -115,5 +117,5 @@ try { } shutdownApiEvent(); // Kill application - process.exit(1); + gracefulExit(1); } diff --git a/api/src/unraid-api/cli/report.spec.ts b/api/src/unraid-api/cli/report.spec.ts deleted file mode 100644 index 5f0e1e670..000000000 --- a/api/src/unraid-api/cli/report.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { beforeAll, expect, test } from 'vitest'; - -import { store } from '@app/store'; -import { loadConfigFile } from '@app/store/modules/config'; -import { anonymiseOrigins } from '@app/unraid-api/cli/report.command'; - -beforeAll(async () => { - // Load cfg into store - await store.dispatch(loadConfigFile()); -}); - -test('anonymise origins removes .sock origins', async () => { - expect(anonymiseOrigins(['/var/run/test.sock'])).toEqual([]); -}); - -test('anonymise origins hides WAN port', async () => { - expect(anonymiseOrigins(['https://domain.tld:8443'])).toEqual(['https://domain.tld:WANPORT']); -});