diff --git a/src/app-init.ts b/src/app-init.ts index 5cb351f07..44109eade 100644 --- a/src/app-init.ts +++ b/src/app-init.ts @@ -79,4 +79,5 @@ export async function setupApp( const { httpAdapter } = app.get(HttpAdapterHost); app.useGlobalFilters(new ErrorExceptionMapping(httpAdapter)); app.useWebSocketAdapter(new WsAdapter(app)); + app.enableShutdownHooks(); } diff --git a/src/main.ts b/src/main.ts index 61c2e3121..7f25ef785 100644 --- a/src/main.ts +++ b/src/main.ts @@ -42,13 +42,6 @@ async function bootstrap(): Promise { // Setup code must be added there! await setupApp(app, appConfig, authConfig, mediaConfig, logger); - /** - * enableShutdownHooks consumes memory by starting listeners. In cases where you are running multiple Nest apps in a - * single Node process (e.g., when running parallel tests with Jest), Node may complain about excessive listener processes. - * For this reason, enableShutdownHooks is not enabled in the tests. - */ - app.enableShutdownHooks(); - // Start the server await app.listen(appConfig.port); logger.log(`Listening on port ${appConfig.port}`, 'AppBootstrap'); diff --git a/test/test-setup.ts b/test/test-setup.ts index 3aac3cafe..1a2a49fb2 100644 --- a/test/test-setup.ts +++ b/test/test-setup.ts @@ -89,6 +89,7 @@ export class TestSetup { } if (connectionOptions.type === 'sqlite') { // Bail out early, as SQLite runs from memory anyway + await this.app.close(); return; } if (appConnection.isConnected) { @@ -106,6 +107,7 @@ export class TestSetup { await connection.close(); } } + await this.app.close(); } }