-
Notifications
You must be signed in to change notification settings - Fork 209
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
Session gets lost if nesting promises #116
Comments
Had to use almost the same approach. |
@AleksMeshkov have you opened a pull request? This will be a problem for anyone using CLS with express. |
@othiym23 Do we need a test for @AleksMeshkov s fix in a pull request? |
Have you tried using Seems likely there is a branch of the execution tree that CLS is not aware of, resulting in the tree resolving early and exiting when some activity is still pending. The most likely cause of that is event emitters as they are not patched automatically. |
I'm using this package to create a session for the current user so I can access session inside nested promises, including mongoose plugins and so on. For whatever reason, the namespace exists too quick and the session get's lost.
I debugged your code a little bit and I came up with this solution for my problem. In context.js line 44 in the Namespace.prototype.run method I patched it like this
Basically I simply exit the namespace on an error and always exit on response finish
This way I am sure that my session is active untill I send back my response to the client
This works for me as intended. Are there any cons to this approach? Looking forward to your feedback
The text was updated successfully, but these errors were encountered: