Skip to content

enableShutdownHooks usage interrupts writing logs via external logger #15978

@dnechay

Description

@dnechay

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using pino as logger for application and enableShutdownHooks, Nest doesn't wait for it to write all logs before exiting.

If app.enableShutdownHooks() is not used and shutdown hooks added manually on process.once for SIGINT/SIGTERM/etc, then pino is able to finish its logging, but if we enable Nest.js shutdown hooks - there is something under the hood that has impact on pino finalization.

Would be nice to understand what is the conflict and how to avoid it to support both.

Minimum reproduction code

https://codesandbox.io/p/devbox/recursing-lamarr-qjh9hh

Steps to reproduce

  1. Clone/fork code
  2. npm install
  3. npm start
  4. Wait app until app is up and running
  5. Press Ctrl+C or send kill -2/kill -15 to pid

Expected behavior

Nest shutdown process doesn't interrupt pino to write all necessary logs that are buffered.

NestJS version

11.1.9

Packages versions

{
  "@nestjs/common": "^11.1.9",
  "@nestjs/core": "^11.1.9",
  "@nestjs/platform-express": "^11.1.9",
  "pino": "^10.1.0",
  "pino-pretty": "^13.1.2",
  "reflect-metadata": "^0.2.2",
  "rxjs": "^7.8.1"
}

Node.js version

v20.12.1 (and others)

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions