Skip to content

Shutdown hooks not working in NestJS when Puppeteer browser is created #14916

@ssljivic

Description

@ssljivic

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When Puppeteer is used, NestJS does not call any onModuleDestroy() methods, although app.enableShutdownHooks() has been called.

Minimum reproduction code

https://github.com/ssljivic/nest-puppeteer-bug

Steps to reproduce

Install packages:
npm i

Start the app without Pupeteer:
npm run dev
Stop the app by pressing Ctrl + C in the terminal
Observe that "OnModuleDestroy start" and "OnModuleDestroy end" are printed.

Start the app with Pupeteer:
WITH_PUPPETEER=true npm run dev
Stop the app by pressing Ctrl + C in the terminal
Observe that "OnModuleDestroy start" and "OnModuleDestroy end" have not been printed.

Expected behavior

Whether Puppeteer is used or not, onModuleDestroy() methods should be called.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.8

Packages versions

{
  "name": "nest-pup",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "license": "UNLICENSED",
  "scripts": {
    "build": "nest build",
    "start": "nest start",
    "dev": "nest start --watch",
    "start:prod": "node dist/main"
  },
  "dependencies": {
    "@nestjs/common": "^10.3.8",
    "@nestjs/core": "^10.3.8",
    "@nestjs/platform-express": "^10.3.8",
    "puppeteer": "^24.6.0"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.3.2",
    "@nestjs/schematics": "^10.1.1",
    "@swc/cli": "^0.3.12",
    "@swc/core": "^1.4.16",
    "@types/express": "^4.17.21"
  }
}

Node.js version

v22.12.0

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