Open jeroen-plug opened 5 years ago
While using cls-hooked
we have also observed that somehow the namespace.active
is null
on some code path.
Interestingly it is available for all functions running inside "most requests", but it is not available when running in services / methods protected by @Security
(i.e. we have set up our own authenticator).
To fix it, for now, we add another middleware in the initialize
of our ServiceAuthenticator
implementation ... But I'd be interested in knowing the actual root cause.
When using
cls-hooked
to store a request context, it does not work if the body parser is used. I made a small example project to reproduce the issue: mwe.zipIgnoring the body works just fine:
curl -X POST http://localhost:3000/nobody -H 'Content-Type: application/json' -d '{"key": "value"}'
If the body is parsed, cls-hooked throws an exception:
curl -X POST http://localhost:3000/body -H 'Content-Type: application/json' -d '{"key": "value"}'
If the body-parser is disabled it works again, but then the body can't be used
curl -X POST http://localhost:3000/noparse -H 'Content-Type: application/json' -d '{"key": "value"}'
Middleware code:
/body
endpoint code: