-
Notifications
You must be signed in to change notification settings - Fork 207
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
How to make this cls work with async function #98
Comments
It's because V8 handles awaited promises with some internal magic rather than actually calling the |
V8 promise hooks should ship with V8 5.7 and should be available in Node 8. |
@ofrobots Nice! Thanks for the update. 👍 |
@ofrobots |
I'm having the same problem as @yizhiheng, node -v 👉 |
Shouldn't this be logged against V8 as well? |
This library will need to migrate to async hooks + promise hooks in order to support async functions. I am not aware of anyone working on this at the moment. |
See cls-hooked. The plan is to eventually PR this into node-continuation-local-storage when we are comfortable with it. |
this code didn't work as i expected. Look like the same problem with this issue. |
FYI - trying this with cls-hooked, I received this: |
Any updates on this? Was attempting to use this library to keep track of trace information for logging in my GraphQL express app and was disappointed to find that the apollo-server-express uses await and i lose context :( Nevermind turns out I just needed to include https://github.com/othiym23/cls-middleware |
Guys, thank you for |
@Jeff-Lewis is it ok to use cls-hooked in production with frozen Node.js version? |
Any updates on this? 🙏 |
@jrpedrianes you can check the discussion here othiym23/async-listener#135 |
Hi all, I am using sequelize-typescript and facing the same issue that transaction does not working Here is my sequelize initialization const ns = clsHooked.createNamespace('sequelize-transaction-namespace');
Sequelize.useCLS(ns); The below code will not working return this.sequelize.transaction(async (trx) => {
await Permit.upsert({
companyId: 1,
userId: 1
});
throw new Error('Should be rollback');
}); If we pass the transaction manually to nested call, it will work return this.sequelize.transaction(async (trx) => {
await Permit.upsert({
companyId: 1,
userId: 1
}, { transaction: trx });
throw new Error('Should be rollback');
}); Does anyone know how to resolve this issue |
Dude, CLS doesn't work with native async/await. You can do what we did, set the target to es5 so that it uses the polyfill instead of the native async/await |
@stormit-vn as you can see above, you need to use |
@rostislavprovodenko I've an issue when setting the target to es6, so this won't work. @santiagodoldan yeah, i also trying cls-hooked as well as native CLS and I think both of them are working with my expectation, but I think the problem is related to the sequelize itself. I am using typescript with native async/await, but sequelize only supports with cls-bluebird. |
@stormit-vn this is what I did
As you can see there you have to assign the namespace to the original Sequelize object, not the one |
@santiagodoldan great. Its working now. Thank you very much! |
@santiagodoldan Works like a charm! Thanks! |
@Jeff-Lewis any update on plans to move cls-hooked code into this codebase or should we consider simply moving to cls-hooked? |
I have below test code, executed in nodejs 7.4.0 with --harmony-async-await argument.
and the output is:
what I think it should be is:
It seems that the context is lost, but when I changed the async function to Generator and ran with co, it works well.
So how can I get it work with async function.
The text was updated successfully, but these errors were encountered: