Skip to content
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

Execution context is also lost with mercurius without enterWith: true #1

Closed
psteinroe opened this issue Oct 5, 2021 · 2 comments · Fixed by #2
Closed

Execution context is also lost with mercurius without enterWith: true #1

psteinroe opened this issue Oct 5, 2021 · 2 comments · Fixed by #2
Labels
bug Something isn't working

Comments

@psteinroe
Copy link
Contributor

psteinroe commented Oct 5, 2021

Hi,

unfortunately, Mercurius also requires enterWith: true to be true. The issue occurs not if using fastify.inject - only with "real clients". I have absolutely no idea why, but that seems to fix it. I opened a PR to replace fastify.inject with supertest in the mercurius e2e test and to set useEnterWith: true. I also updated the documentation accordingly.

@psteinroe psteinroe changed the title Execution context is lost with mercurius without enterWith: true Execution context is also lost with mercurius without enterWith: true Oct 5, 2021
@Papooch Papooch added the bug Something isn't working label Oct 5, 2021
@Papooch Papooch closed this as completed in #2 Oct 5, 2021
@Papooch
Copy link
Owner

Papooch commented Oct 5, 2021

That's really unfortunate :( That means there's really no 100% safe way to use cls with GQL, because AsyncLocalStorage.enterWith() can leak context between concurrent calls.

Thanks for the PR, I have merged it, and I will publish it with a new version in a couple of days.

I'll have to do some more tests to verify that no context is leaked in a request after it goes past the ClsMiddleware, but I fear the worst. (I have discovered that I can access the context of the previous request before enter is called in the middleware)

@Papooch
Copy link
Owner

Papooch commented Jul 10, 2023

This now works with both apollo and mercurius with the latest release of @nestjs/graphql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants