Skip to content

Commit d1469ca

Browse files
committed
docs(lifecycle-events): memory leaks of app shutdown
1 parent deee283 commit d1469ca

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

content/fundamentals/lifecycle-events.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The following diagram depicts the sequence of key application lifecycle events,
1515
Lifecycle events happen during application bootstrapping and shutdown. Nest calls registered lifecycle hook methods on `modules`, `injectables` and `controllers` at each of the following lifecycle events (**shutdown hooks** need to be enabled first, as described [below](https://docs.nestjs.com/fundamentals/lifecycle-events#application-shutdown)). As shown in the diagram above, Nest also calls the appropriate underlying methods to begin listening for connections, and to stop listening for connections.
1616

1717
| Lifecycle hook method | Lifecycle event triggering the hook method call |
18-
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18+
|-------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1919
| `onModuleInit()` | Called once the host module's dependencies have been resolved. |
2020
| `onApplicationBootstrap()` | Called once all modules have been initialized, but before listening for connections. |
2121
| `onModuleDestroy()` | Called after a termination signal (e.g., `SIGTERM`) has been received. |
@@ -83,6 +83,8 @@ async function bootstrap() {
8383
bootstrap();
8484
```
8585

86+
> info **Info** `enableShutdownHooks` is disabled by default because the application could run into memory leak issues in case multiple Nest instances are running (e.g. testing). Node.js would warn you, in case you have too many listeners running in parallel and prevent you from having major memory leaks.
87+
8688
When the application receives a termination signal it will call any registered `beforeApplicationShutdown()`, then `onApplicationShutdown()` methods (in the sequence described above) with the corresponding signal as the first parameter. If a registered function awaits an asynchronous call (returns a promise), Nest will not continue in the sequence until the promise is resolved or rejected.
8789

8890
```typescript

0 commit comments

Comments
 (0)