-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
asyncLocalStorage returns undefined if the request body is not empty (post, patch ...) #37207
Comments
probems when the body is written in json format |
Hi @LoginovSO, thanks for opening this report! could you please provide some code snippet to reproduce this behavior? That would be very appreciated. |
I hope you will understand |
Is this still an issue with Node.js 14.17.4? |
I have a similar issue when using express and a body parser middleware. When body parser is executed, e.g. by matching content type (application/xml) of incoming request, then in the following controller, async store will be undefined. |
Btw. thanks for the workaround with |
Working code sample below.
code:
|
I suppose, this is related stream-utils/raw-body#71 |
The docs mention a caveat with using I don't believe I fully understand why |
@wolfejw86 The difference is that const server = http.createServer();
server.on("request", (req, res) => {
// this effects also the other listeners below and the whole code executed within node http module after `emit("request", req, res)` returned
als.enterWith(myStore1);
// here comes your code
});
server.on("request", (req, res) => {
// this effects only the code in given callback but not the other listener below nor node http internals
als.run(() => {
}, myStore2);
});
server.on("request", (req, res) => {
// myStore1 is still active here, myStore2 is not
}); If |
@Flarna Thanks for that - that confirms what I know about it except for one part- do you have to call exit manually? Say I only have one request handler listener, and I’m using enterWith at the start of each one. The contexts still appear to get cleaned up, there’s just the fact that the “previous context” is accessible by the next request until I start the next cycle of enterWith -> run right? |
if calling
When an async resource gets destroyed depends on the resource. e.g. I know that this is not that easy to understand. You could use async hooks to monitor init/enter/exit/destroy of resources in some experiment to get some better insight. |
Did anything change about this or would it still be recommended to use enterWith when creating a async local storage with express using Node.js v20? |
node v14.6.0
Additional information
returns undefined if the request body is not empty (post, patch ...)
when using async localStorage. run ()
but when using async localStorage.enter With() everything works fine
The text was updated successfully, but these errors were encountered: