CLS context is not active #133
-
Hello again, @Papooch As we recently discussed an approach for manual In my guard, I have something like this:
Then, down the callback chain I have a service that needed that
Am I doing something wrong? I thought that a context would be unique for each request. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
What do you mean by context not being active after first request? Could you provide a minimal reproduction? I don't think I'll be able to help you without one. |
Beta Was this translation helpful? Give feedback.
I was able to reporoduce it on latest version of Nest. When I use the
ClsGuard
fromnestjs-cls
, it does not suffer from the same issue (due to not awaiting anything before entering).That said, the
.enterWith
method is still experimental, so bugs like these are not that surprising. Therefore I am afraid that I can't fix this in the library.As you also discovered, the fix is to run it synchronously, so I would propose changing the logic in the guard so that any
awaited
calls are executed only aftercls.enterWith
is called. The function can still be marked async, because Node runs all code within anasync
function synchronously, until the firstawait
.If you want to be sure, create the pro…