Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
async-hooks: introduce async-storage API#26540
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
This comment has been minimized.
This comment has been minimized.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
mscdex left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this is best left as a userland module, especially considering it can be fairly easily implemented using just async_hooks. There are also some assumptions being made design-wise here that others might disagree with and would want more flexibility.
Even if this kind of feature were to be added to node core, it would be better to have it start in userland to allow easier iteration on the idea first, to figure out the best API and behaviors between all parties that would be involved.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
addaleax commented Mar 9, 2019
@mscdex This was talked about at the diagnostics summit. I don’t think the feature has to exist in this particular form, but having it in core made sense in general, and in particular performance-wise, since a good implementation could allow us to skip calling FYI @nodejs/tsc |
mcollina commented Mar 9, 2019
I think this functionality belongs in core. We should offer a single way to do cls that is high performant, stable and reliable. It’s not an ecosystem concern, it’s a runtime concern (as much as a ThreadLocal implementation is for Java/.NET/.. etc). |
doc/api/async_storage.md Outdated
| @@ -0,0 +1,86 @@ | |||
| # Async Storage | |||
| <!--introduced_in=v12.x.x--> | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to be added: REPLACEME ? Does introduced_in work also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jasnell commented Mar 9, 2019
I agree that this should be in core and there was consensus among the @nodejs/diagnostics WG members attending the diagnostics summit. Sure, we can bikeshed around the specific API, and I would like to get some of the APM vendors to review this before it lands, it would be generally better to have a single authoritative API and implementation of this than multiple userland implementations so that APM solutions built on top can be implemented consistently. |
vsemozhetbyt commented Mar 9, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Should we create npm placeholder for this name as per our guide? |
mcollina commented Mar 9, 2019 via email
Go ahead. I kind of expect this to go under `@nodejs/async-storage` but better safe than sorry. Il giorno sab 9 mar 2019 alle ore 13:10 Vse Mozhet Byt < [email protected]> ha scritto: … Should we create npm placeholder for this name as per our guides? — You are receiving this because your review was requested. Reply to this email directly, view it on GitHub <#26540 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AADL4xdIdUUD6v4zX5DYe6C_E1y5GCinks5vU6SmgaJpZM4bmmI4> . |
vsemozhetbyt commented Mar 9, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Sorry, I am not experienced in registering placeholders in npm, so anybody more confident please do it. |
mcollina commented Mar 9, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There is https://www.npmjs.com/package/async-storage, which makes calling this module |
jasnell commented Mar 9, 2019
Does this require a separate new top level module? Could this be exposed alternatively through the existing async_hooks module? Or via util? |
vdeturckheim commented Mar 9, 2019
@jasnell I actually think it would make sense to have that in |
vdeturckheim commented Mar 9, 2019
I will update the PR over the week end and start to contact APM and RASP vendors to ensure thay can comment. Thanks a lot to all of you for the comments and suggestions! |
devsnek commented Mar 9, 2019
if this is going to be in core I'd want it to be more similar to https://github.com/WICG/kv-storage |
jasnell commented Mar 9, 2019
@vdeturckheim ... One thing to consider is that by putting this into a new module, it automatically becomes semver-major and significantly harder to backport. My hope is that we could at least get this into 10.x also. |
vdeturckheim commented Mar 9, 2019
devsnek commented Mar 9, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@vdeturckheim reading over this again it seems i was confused as to what this pr is adding to node. i think it might lend itself better to a different name like "async_closure" or "async_context" something. i'd be strongly in favor of making the class available as an |
targos commented Mar 9, 2019
I think it would be better placed in |
othiym23 commented Mar 9, 2019
As a developer and co-maintainer of |
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Notable changes: * async_hooks * introduce async-context API (vdeturckheim) #26540 * stream * support passing generator functions into pipeline() (Robert Nagy) #31223 * tls * expose SSL\_export\_keying\_material (simon) #31814 * vm * implement vm.measureMemory() for per-context memory measurement (Joyee Cheung) #31824 PR-URL: #32027
Sytten commented Mar 6, 2020
Any chance this will be backported to v12? |
puzpuzpuz commented Mar 6, 2020
It would be great to have Note: |
Qard commented Mar 6, 2020
As far as I know, backporting |
Flarna commented Mar 6, 2020
Care must be taken to include also the followup PRs fixing various bugs found afterwards. |
puzpuzpuz commented Mar 6, 2020
I've created a backport PR for |
codebytere commented Mar 16, 2020
@puzpuzpuz thanks! this next release is a patch so it'll go out in the subsequent minor. |
puzpuzpuz commented Mar 17, 2020
v12 backport: #32318 |
Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <[email protected]> PR-URL: nodejs#26540 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <[email protected]> PR-URL: nodejs#26540 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <[email protected]> PR-URL: #26540 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
indutny commented Jul 16, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Providing a reference to another issue here because most interested parties are subscribed to this issue. |

This introduces a new API in core to provide asynchronous storage features.
More and more Node.js users have been needing such API to:
Some userland modules exist but they:
Havin such API in core will make the ecosystem more stable and reliable when needing an asynchronous storage.
This is still an early work and there is probably a lot of updates to do to this PR :)
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes