Skip to content

Jest breaks AsyncLocalStorage when running Node 16.2.0 #11435

@kibertoad

Description

@kibertoad

🐛 Bug Report

See https://github.com/stephenh/async-local-storage-repro, DataDog/dd-trace-js#1095, fastify/fastify-request-context#49, or try running tests from https://github.com/puzpuzpuz/cls-rtracer with Node 16.2.0

Change in 16.2.0 that is causing this: nodejs/node#36394
More detailed analysis on the root cause for the issue: nodejs/node#38781

To Reproduce

If you run code that does:

  1. access AsyncLocalStorage.getStore
  2. await a promise
  3. access AsyncLocalStorage.getStore again, on node 16.2.0 and jest,

the getStore value is lost and comes back as undefined.

Expected behavior

AsyncLocalStorage should work as it did on previous versions with Node 16.2.0 and Jest, returning previously set value

Link to repl or repo (highly encouraged)

https://github.com/stephenh/async-local-storage-repro
https://github.com/puzpuzpuz/cls-rtracer (run tests with Node 16.2.0)
https://github.com/fastify/fastify-request-context/ (run npm run test:jest with Node 16.2.0)

envinfo

  System:
    OS: Windows 10 10.0.19041
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
  Binaries:
    Node: 16.2.0 - C:\software\node\node.EXE
    Yarn: 1.22.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 7.13.0 - C:\software\node\npm.CMD
  npmPackages:
    jest: ^26.6.3 => 26.6.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions