Skip to content

nest start doesn't wait for asynchronous shutdown hooks #3158

@MrBartusek

Description

@MrBartusek

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Running nest start and then terminating the application using CTRL+C doesn't await asynchronous shutdown hooks (onModuleDestroy, beforeApplicationShutdown, onApplicationShutdown). Instead, the process exits before they are completed, but the application still completes gracefully.

Image

Things I've tried:

  1. app.enableShutdownHooks(); is enabled
  2. I've found a similar issue getting EADDRINUSE error when using start with watch mode with an async beforeApplicationShutdown #1614 that was fixed by --no-shell; however, it doesn't resolve the problem here.

Minimum reproduction code

https://github.com/MrBartusek/shutdown-bug

Steps to reproduce

  1. Clone and setup my repo https://github.com/MrBartusek/shutdown-bug. Only changes are in app.module.ts https://github.com/MrBartusek/shutdown-bug/blob/master/src/app.module.ts
  2. Run nest start
  3. Terminate using CTRL+C
  4. See error

Expected behavior

Running node dist/main waits for shutdown correctly, I would expect it would work the same here

Image

Package version

11.0.10

NestJS version

11.1.6

Node.js version

20.19.2

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

I'am using WSL with Ubuntu 22.04.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions