Is there an existing issue for this?
Current behavior
If any provider's onModuleDestroy, beforeApplicationShutdown, or onApplicationShutdown hook throws or rejects, Promise.all fails fast and the following seem to be silently skipped:
remaining providers in the same module
transient-scoped providers in that module
the module class instance's own hook
all subsequent modules in the shutdown sequence
This means DB connections, file handles, message queue connections, etc. could be left open on shutdown.
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-cmw828to?file=src%2Fmain.ts
Steps to reproduce
- Register two providers that implement
OnModuleDestroy
- Make the first provider's hook throw/reject
- Send SIGTERM (or call
app.close())
- Observe that the second provider's hook is never called
In Reproduction Code(CodeSandbox)
- Register two providers that implement
OnModuleDestroy
- Make the first provider's hook throw/reject
- Call
app.close() (or send SIGTERM)
- Observe that
"FileService: cleanup called" is never printed in the console. (Which means FileService's onModuleDestroy is never called
Expected behavior
All providers should attempt their cleanup regardless of failures in sibling providers. Individual hook errors should be logged, but shouldn't stop the rest of the shutdown sequence — similar to how Promise.allSettled works.
NestJS version
11.1.24
Packages versions
Node.js version
24.0.0
In which operating systems have you tested?
Other
No response
Is there an existing issue for this?
Current behavior
If any provider's
onModuleDestroy,beforeApplicationShutdown, oronApplicationShutdownhook throws or rejects,Promise.allfails fast and the following seem to be silently skipped:remaining providers in the same module
transient-scoped providers in that module
the module class instance's own hook
all subsequent modules in the shutdown sequence
This means DB connections, file handles, message queue connections, etc. could be left open on shutdown.
Minimum reproduction code
https://stackblitz.com/edit/nestjs-typescript-starter-cmw828to?file=src%2Fmain.ts
Steps to reproduce
OnModuleDestroyapp.close())Expected behavior
All providers should attempt their cleanup regardless of failures in sibling providers. Individual hook errors should be logged, but shouldn't stop the rest of the shutdown sequence — similar to how
Promise.allSettledworks.NestJS version
11.1.24
Packages versions
@nestjs/core: 11.1.10Node.js version
24.0.0
In which operating systems have you tested?
Other
No response