Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Explicitly enable framework shutdown hooks
A cleanup lifecycle hook only fires on process signals if the framework's shutdown-hook wiring is explicitly enabled at bootstrap.
Bad example
| 1 | async function bootstrap() { |
| 2 | const app = await NestFactory.create(AppModule, { bufferLogs: true }); |
| 3 | await app.listen(3000); |
| 4 | } |
Explanation (EN)
Defining an `onModuleDestroy`/cleanup lifecycle hook does nothing by itself if the framework requires an explicit opt-in to wire OS signals (SIGTERM/SIGINT) to the shutdown sequence; on a container platform the process is killed directly and cleanup never runs.
Objašnjenje (HR)
Definiranje `onModuleDestroy`/cleanup lifecycle hooka samo po sebi ne radi ništa ako framework zahtijeva eksplicitni opt-in da poveže OS signale (SIGTERM/SIGINT) sa shutdown sekvencom; na kontejnerskoj platformi proces se ubije direktno i cleanup se nikad ne izvrši.
Good example
| 1 | async function bootstrap() { |
| 2 | const app = await NestFactory.create(AppModule, { bufferLogs: true }); |
| 3 | app.enableShutdownHooks(); |
| 4 | await app.listen(3000); |
| 5 | } |
Explanation (EN)
Enable the framework's shutdown-hook mechanism explicitly during bootstrap so signal-triggered shutdowns actually invoke your cleanup hooks — then verify it with a real signal or an integration test, not just an e2e test that calls `.close()` directly.
Objašnjenje (HR)
Eksplicitno uključi framework-ov shutdown-hook mehanizam tijekom bootstrapa kako bi gašenje pokrenuto signalom stvarno pozvalo tvoje cleanup hookove — zatim to provjeri stvarnim signalom ili integracijskim testom, ne samo e2e testom koji direktno zove `.close()`.
Notes (EN)
The exact API call is framework-specific (e.g. NestJS's `app.enableShutdownHooks()`), but the general pattern — cleanup hooks needing an explicit signal-wiring opt-in — recurs across frameworks.
Bilješke (HR)
Točan API poziv ovisi o frameworku (npr. NestJS-ov `app.enableShutdownHooks()`), ali opći obrazac — da cleanup hookovi trebaju eksplicitni opt-in za povezivanje signala — ponavlja se kroz razne frameworke.