Skip to content

AsyncLocalStorage context is lost with global interceptors #15317

Closed
@darcyrush

Description

@darcyrush

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I can chain multiple interceptors with observables to persist the current AsyncLocalStorage context, but when an error is thrown anywhere in the project, the context is lost at the global exception filter

Minimum reproduction code

https://github.com/darcyrush/nestjs-async-local-storage

Steps to reproduce

  1. npx ts-node src/main
  2. curl -H "x-id: 123" http://localhost:3000/success
  3. curl -H "x-id: 123" http://localhost:3000/failure

Expected behavior

I expect some way to propagate the AsyncLocalStorage callback to the global exception filter

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

11.1.3

Packages versions

"@nestjs/common": "^11.1.3",
"@nestjs/core": "^11.1.3",
"@nestjs/platform-express": "^11.1.3",

Node.js version

24.0.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

I asked already in the NestJS Discord; thread here

It appears that this may be an issue with HTTP specifically; Papooch/nestjs-cls#5

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