-
Notifications
You must be signed in to change notification settings - Fork 89
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
Context lost when awaiting on custom thenable #37
Comments
@vkarpov15 ! Sorry I haven't gotten to this. I'm a little fuzzy on what mongoose's |
This is caused by an issue in Node where the context is restored by the Promise class and not the |
@Jeff-Lewis I've been looking more into this issue and found something you might find interesting: this issue only happens with const clsHooked = require('cls-hooked');
const session = clsHooked.createNamespace('mytest');
session.runPromise(run);
async function run() {
session.set('test', '42');
const thenable = {
then: (resolve, reject) => {
console.log('Session', session.get('test')); // undefined
return Promise.resolve('').then(resolve, reject);
}
};
await thenable; // This is the problem, context gets lost in `then()`
// This works fine
await new Promise((resolve, reject) => {
console.log('Session2', session.get('test')); // 42
});
} It seems like this only happens if you start using async functions inside of |
@vkarpov15 If your issue is caused by the bug in Node, it should be fixed by this PR in |
Not sure if this is an issue or expected behavior, but figured I'd ask. I've been tracking down a bug with mongoose and express-http-context, and found that if you use
await
with a customthen()
function, context goes away. Here's an example:Any ideas as to what might be going on here?
Re: Automattic/mongoose#7292
The text was updated successfully, but these errors were encountered: