GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — async_hooks: prevent async storage methods leaking to outer context by Qard · Pull Request #31950 · nodejs/node

Conversation

@Qard

@Qard Qard commented Feb 25, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The _exit logic is not actually necessary as explained here. This eliminates it and gives sync context runs a proper AsyncResource.

cc @vdeturckheim @puzpuzpuz @Flarna

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss, himself65, and puzpuzpuz reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@Qard Qard added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. async_hooks Issues and PRs related to the async hooks subsystem. labels Feb 25, 2020
@Qard Qard self-assigned this Feb 25, 2020
@Qard Qard changed the title Async storage eliminate exit transition async_hooks: eliminate _exit in async storage Feb 25, 2020
@Qard

Qard commented Feb 25, 2020

Copy link
Copy Markdown
Member Author

Also, with the addition of the AsyncResource in the *SyncAndReturn methods, I'm not convinced we still need separate sync and async methods.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard Qard mentioned this pull request Feb 25, 2020
async_hooks: add sync enterWith to async storage #31945
Closed
4 tasks done
vdeturckheim
vdeturckheim suggested changes Feb 25, 2020
View reviewed changes

@vdeturckheim vdeturckheim left a comment

Copy link
Copy Markdown
Member

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.

Couple comments, also, I am afraid this comes with a perf cost in the *SyncAndReturn(...) methods

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Qard

Qard commented Feb 25, 2020

Copy link
Copy Markdown
Member Author

Yes, there would be some perf cost to the AsyncResource, however it's the more correct way to handle this and the perf impact should be fairly minimal as AsyncResource skips the native side of async_hooks, instead just calling the lifecycle handlers directly..

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vdeturckheim

vdeturckheim commented Feb 25, 2020

Copy link
Copy Markdown
Member

Yes, there would be some perf cost to the AsyncResource, however it's the more correct way to handle this and the perf impact should be fairly minimal as AsyncResource skips the native side of async_hooks, instead just calling the lifecycle handlers directly..

Because of _propagate that would still mean that the perf impact of calling it grows with the current number of active instances of AsyncLocalStorage. I'd prefer to avoid calling the init hook alltogether in the sync track.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vdeturckheim
vdeturckheim reviewed Feb 25, 2020
View reviewed changes
Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

puzpuzpuz
puzpuzpuz reviewed Feb 25, 2020
View reviewed changes
Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@puzpuzpuz

puzpuzpuz commented Feb 25, 2020

Copy link
Copy Markdown
Member

This PR was aimed to fix nested .run*() calls problem discussed here: #31945 (comment)

Yet, I don't see any tests that verify the fix.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard

Qard commented Feb 26, 2020

Copy link
Copy Markdown
Member Author

No it wasn't, I made this as an improvement not as a fix. I can rework it to verify that it fixes that too though, if you want, as it probably does.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard

Qard commented Feb 26, 2020

Copy link
Copy Markdown
Member Author

Added a test to verify it fixes that issue.

puzpuzpuz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard Qard changed the title async_hooks: eliminate _exit in async storage async_hooks: prevent sync async storage methods from exiting outer context Feb 26, 2020
@Qard Qard changed the title async_hooks: prevent sync async storage methods from exiting outer context async_hooks: prevent sync methods of async storage exiting outer context Feb 26, 2020
@Qard

Qard commented Feb 26, 2020

Copy link
Copy Markdown
Member Author

I restored the _exit method as the PR is not really about that anymore.

Also, what do you all think about just making the *SyncAndReturn methods into the base methods and eliminating the existing run and exit? They are somewhat redundant as they are functionally pretty much the same with the AsyncResource in there. The only difference being the callback is not actually executed async, which I don't think actually matters. If anything, I'd find it a bit unexpected that they are async by default. It's similar to the function given to a new Promise, in my opinion. 🤔

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@puzpuzpuz

puzpuzpuz commented Feb 26, 2020

Copy link
Copy Markdown
Member

I restored the _exit method as the PR is not really about that anymore.

Also, what do you all think about just making the *SyncAndReturn methods into the base methods and eliminating the existing run and exit?

I like the idea of keeping only a single pair of methods. But I'd rather rename *SyncAndReturn into run and exit and update their documentation. It doesn't make sense to use longer names when there are no alternative methods.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Flarna
Flarna reviewed Feb 26, 2020
View reviewed changes
Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Qard Qard added the blocked PRs that are blocked by other issues or PRs. label Feb 26, 2020
@vdeturckheim

vdeturckheim commented Feb 26, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@Qard I don't really understand the benchmarks, did you delete one message? Also, if I understand well, we still introduce a perf impact on the sync path that grows with the number of concurent instances. I'd like to avoid this case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard

Qard commented Feb 26, 2020

Copy link
Copy Markdown
Member Author

Yes, I deleted a comment awhile ago as I ran the benchmark wrong. The correct benchmark is the one in the thread near the top of the PR. It shows that the performance difference is basically non-existent.

vdeturckheim reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard Qard removed the blocked PRs that are blocked by other issues or PRs. label Feb 28, 2020
@Qard
Qard force-pushed the async-storage-eliminate-exit-transition branch from 5e07676 to 2b6a63c Compare February 28, 2020 05:51
@Qard

Qard commented Feb 28, 2020

Copy link
Copy Markdown
Member Author

Rebased as #31930 has landed now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard
Qard force-pushed the async-storage-eliminate-exit-transition branch from 2b6a63c to 23a0772 Compare February 28, 2020 06:15
puzpuzpuz
puzpuzpuz reviewed Feb 28, 2020
View reviewed changes
Comment thread lib/async_hooks.js Resolved

Uh oh!

There was an error while loading. Please reload this page.

@puzpuzpuz puzpuzpuz mentioned this pull request Feb 28, 2020
test: improve disable AsyncLocalStorage test #31998
Closed
3 tasks done
@vdeturckheim

vdeturckheim commented Feb 28, 2020

Copy link
Copy Markdown
Member

Probably worth waiting for #31998 to land first

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard
Qard force-pushed the async-storage-eliminate-exit-transition branch from 417ff73 to 2db2994 Compare March 1, 2020 06:51
@puzpuzpuz puzpuzpuz added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 14, 2020
@puzpuzpuz

puzpuzpuz commented Apr 14, 2020

Copy link
Copy Markdown
Member

Marked this one with semver-minor label, as it shouldn't land in a patch release. Let me know if you don't feel the same.

targos and Qard reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BethGriggs BethGriggs mentioned this pull request Apr 14, 2020
2020-04-21, Version 14.0.0 (Current) #32181
Merged
puzpuzpuz added a commit to puzpuzpuz/node that referenced this pull request Apr 14, 2020
@puzpuzpuz
async_hooks: merge run and exit methods
c6f7f55
PR-URL: nodejs#31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
@puzpuzpuz puzpuzpuz mentioned this pull request Apr 14, 2020
v13.13.0 release proposal #32813
Merged
@Qard

Qard commented Apr 14, 2020

Copy link
Copy Markdown
Member Author

Sounds fine to me. 👍

puzpuzpuz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

targos added a commit to targos/async-http-context that referenced this pull request Apr 24, 2020
@targos
fix: use run method and throw error used outside of context
4e690d3
`runSyncAndReturn` was removed from Node.js in nodejs/node#31950
@targos targos mentioned this pull request Apr 24, 2020
fix: use run method and throw error used outside of context RomainLanz/async-http-context#1
Merged
@targos targos removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Apr 25, 2020
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
@Qard @targos
async_hooks: prevent sync methods of async storage exiting outer context
e61bcd2
PR-URL: nodejs#31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
@puzpuzpuz @targos
async_hooks: merge run and exit methods
ccbf4f9
PR-URL: nodejs#31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
BridgeAR pushed a commit that referenced this pull request Apr 28, 2020
@Qard @BridgeAR
async_hooks: prevent sync methods of async storage exiting outer context
b304df9
PR-URL: #31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
BridgeAR pushed a commit that referenced this pull request Apr 28, 2020
@puzpuzpuz @BridgeAR
async_hooks: merge run and exit methods
52d8afc
PR-URL: #31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Apr 28, 2020
v13.14.0 proposal #33122
Merged
BridgeAR added a commit that referenced this pull request Apr 28, 2020
@BridgeAR
2020-04-28, Version 13.14.0 (Current)
9862aba
Notable Changes:

* async_hooks**:
  * Merge `run` and `exit` methods (Andrey Pechkurov)
    #31950
  * Prevent sync methods of async storage exiting outer context
    (Stephen Belanger)
    #31950
* vm:
  * Add `importModuleDynamically` option to compileFunction (Gus
    Caplan)
    #32985

New core collaborators:

With this release, we welcome two new Node.js core collaborators:

* Juan José Arboleda @juanarbol
  #32906
* Andrey Pechkurov @puzpuzpuz
  #32817

PR-URL: #33122
targos pushed a commit that referenced this pull request Apr 28, 2020
@Qard @targos
async_hooks: prevent sync methods of async storage exiting outer context
3eb3406
PR-URL: #31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
targos pushed a commit that referenced this pull request Apr 28, 2020
@puzpuzpuz @targos
async_hooks: merge run and exit methods
a35e88c
PR-URL: #31950
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
BridgeAR added a commit that referenced this pull request Apr 28, 2020
@BridgeAR
2020-04-29, Version 13.14.0 (Current)
9fc74f1
Notable Changes:

* async_hooks**:
  * Merge `run` and `exit` methods (Andrey Pechkurov)
    #31950
  * Prevent sync methods of async storage exiting outer context
    (Stephen Belanger)
    #31950
* vm:
  * Add `importModuleDynamically` option to compileFunction (Gus
    Caplan)
    #32985

New core collaborators:

With this release, we welcome two new Node.js core collaborators:

* Juan José Arboleda @juanarbol
  #32906
* Andrey Pechkurov @puzpuzpuz
  #32817

PR-URL: #33122
BridgeAR added a commit that referenced this pull request Apr 29, 2020
@BridgeAR
2020-04-29, Version 13.14.0 (Current)
d7b02c3
Notable Changes:

* async_hooks**:
  * Merge `run` and `exit` methods (Andrey Pechkurov)
    #31950
  * Prevent sync methods of async storage exiting outer context
    (Stephen Belanger)
    #31950
* vm:
  * Add `importModuleDynamically` option to compileFunction (Gus
    Caplan)
    #32985

New core collaborators:

With this release, we welcome two new Node.js core collaborators:

* Juan José Arboleda @juanarbol
  #32906
* Andrey Pechkurov @puzpuzpuz
  #32817

PR-URL: #33122
@targos targos mentioned this pull request May 2, 2020
v12.17.0 release proposal #33197
Merged
@kibertoad

kibertoad commented May 4, 2020

Copy link
Copy Markdown
Contributor

@Qard Sorry if I misunderstand something, but was this merged only to 12.x but not to 14.x?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@legendecas

legendecas commented May 4, 2020

Copy link
Copy Markdown
Member

@kibertoad a683e87 is the commit that landed on 14.x branch and is released with v14.0.0.

puzpuzpuz and kibertoad reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Qard
Qard deleted the async-storage-eliminate-exit-transition branch May 4, 2020 18:05
@vmarchaud vmarchaud mentioned this pull request Jun 18, 2020
AsyncLocalStorage based ContextManager open-telemetry/opentelemetry-js#1210
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Flarna Flarna Flarna approved these changes
+2 more reviewers
@puzpuzpuz puzpuzpuz puzpuzpuz left review comments
@vdeturckheim vdeturckheim vdeturckheim approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@Qard Qard

Labels

async_hooks Issues and PRs related to the async hooks subsystem. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@Qard @vdeturckheim @puzpuzpuz @Flarna @nodejs-github-bot @addaleax @kibertoad @legendecas @targos @himself65
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.