AsyncLocalStorage context is lost when working with Readable stream

Hi, When using MongoDB node.js driver with AsyncLocalStorage with Readable stream, asyncLocalStorage context is lost

minimal example of reproduction:

const { AsyncLocalStorage } = require('async_hooks')
const asyncLocalStorage = new AsyncLocalStorage()
asyncLocalStorage.run({ requestId: Math.random() }, async () => {
  const findStream = await mongoConnection.collection('test').find(filter).stream();
  findStream.on('end', () => {
     asyncLocalStorage.getStore(); // requestId is lost here
 });
});

Reproduced on:

NodeJs: 16.15.1
mongoDB node.Js version: 3.7.3

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.