node
node copied to clipboard
AsyncLocalStorage seems to mix-up context using Node 16.20.2-2
Version
16.20.2-2-cm2.0.20231106
Platform
Mariner - linux
Subsystem
No response
What steps will reproduce the bug?
Seeing this in production systems, only reproducible by traces
static runInContext<T>(func: () => Promise<T>): Promise<T> {
const store: Map<string, any> = new Map([[REQUEST_CONTEXT_ID, Guid.create().toString()]]);
return ContextManager.als.run(store, () => {
logger.info('f97d2b0c-3c47-47eb-8764-05c45494ff05', `${ContextManager.runInContext.name} - Running in context request-context-id ${store.get(REQUEST_CONTEXT_ID)}`);
return func();
});
}
This is being triggered by a middleware, there is a code later down the line that will set add store, what we can see is that one context is being replaced by an other call, both calls are getting called nearly at the same time
How often does it reproduce? Is there a required condition?
Pretty frequent, it seems whenever there are 2 API calls arriving at the same time
What is the expected behavior? Why is that the expected behavior?
I would expect for both context to not override
What do you see instead?
2 different context running in the same context
Additional information
No response
can you provide a repro? No external dependencies
external dependencies in what way ? unfortunately i only see it in prod env when 2 requests come in simultaneity, I was unable to repo this locally has hard as I tried, it seems that the set will see some values on a different context
Facing the same issue. Any resolution here?
v16 is EOL, can you check with newer version? If so please open a new issue with a repro
I have seen the similar issue with the cls module for nestjs. And it happened in a way just as you described.