Skip to content
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

http,async_hooks: keep resource object alive from socket #30196

Closed
wants to merge 1 commit into from

Conversation

addaleax
Copy link
Member

If asyncReset() is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: #30122

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

FYI @Flarna

If `asyncReset()` is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: nodejs#30122
@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Oct 31, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

// AsyncWrap::AsyncReset() when the resource is not the AsyncWrap object
// itself. However, HTTPClientAsyncResource and HTTPServerAsyncResource
// hold on to other objects, inhibiting GC.
handle[kReusedHandle] = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok that on second reuse of the handle the binding to the first ReusedHandle is removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Flarna That only happens together with a destroy emitted before and a new ID assigned, so I’m pretty confident it’s safe to discard the first ReusedHandle at that point

@Flarna
Copy link
Member

Flarna commented Oct 31, 2019

Thanks for fixing this!
An alternative would be to revert 3d9d1ad as it seems the initial idea from diag summit to move towards resource based API is no longer in focus. I did that change because it was a low hanging fruit to move towards the direction.

But it seems that the use of AsyncHooks by domains is in general risky as there might be other users not using an AsyncWrap. For example if someone uses napi_async_init() with async_resource == nullptr a new object is created and used in init call but then no longer referenced.

@addaleax
Copy link
Member Author

@Flarna I do still feel that moving towards a resource-based API makes sense, it just needs somebody with sufficient time and resources to push it through.

Thanks for pointing out the N-API issue, that seems indeed like a problem of the kind already mentioned in the TODO comment here…

@addaleax addaleax added the review wanted PRs that need reviews. label Nov 4, 2019
@addaleax
Copy link
Member Author

addaleax commented Nov 4, 2019

@nodejs/domains @nodejs/async_hooks

Copy link
Member

@vdeturckheim vdeturckheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. async_hooks Issues and PRs related to the async hooks subsystem. domain Issues and PRs related to the domain subsystem. labels Nov 5, 2019
@addaleax addaleax removed the review wanted PRs that need reviews. label Nov 6, 2019
@addaleax
Copy link
Member Author

addaleax commented Nov 6, 2019

Landed in d26a74d

@addaleax addaleax closed this Nov 6, 2019
addaleax added a commit that referenced this pull request Nov 6, 2019
If `asyncReset()` is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: #30122

PR-URL: #30196
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@addaleax addaleax deleted the async-hooks-domain-gc-30122 branch November 6, 2019 11:34
@HazAT
Copy link

HazAT commented Nov 7, 2019

@addaleax Hello and thank you from Sentry 👋 😄 🎉

MylesBorins pushed a commit that referenced this pull request Nov 17, 2019
If `asyncReset()` is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: #30122

PR-URL: #30196
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Nov 19, 2019
targos pushed a commit that referenced this pull request Dec 1, 2019
If `asyncReset()` is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: #30122

PR-URL: #30196
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@BethGriggs BethGriggs mentioned this pull request Dec 9, 2019
MylesBorins pushed a commit that referenced this pull request Dec 17, 2019
If `asyncReset()` is used to specify an alternative resource object
to mark a re-used socket in the HTTP Agent implementation,
store that object and keep it alive, because domains rely on GC tracking
for resource objects to manage their own lifetimes, and previously that
resource object might have been garbage-collected too early, leading to
crashes.

Fixes: #30122

PR-URL: #30196
Reviewed-By: Vladimir de Turckheim <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@BethGriggs BethGriggs mentioned this pull request Dec 23, 2019
addaleax pushed a commit that referenced this pull request Mar 11, 2020
Remove the reference from handle to the unique/wrapping resource
ReusedHandle as there is meanwhile a strong reference for all async
resources in place via AsyncWarp::resource_.

PR-URL: #32054
Refs: #30959
Refs: #30196
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 11, 2020
Remove the reference from handle to the unique/wrapping resource
ReusedHandle as there is meanwhile a strong reference for all async
resources in place via AsyncWarp::resource_.

PR-URL: #32054
Refs: #30959
Refs: #30196
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
MylesBorins pushed a commit that referenced this pull request Mar 11, 2020
Remove the reference from handle to the unique/wrapping resource
ReusedHandle as there is meanwhile a strong reference for all async
resources in place via AsyncWarp::resource_.

PR-URL: #32054
Refs: #30959
Refs: #30196
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit to targos/node that referenced this pull request Apr 25, 2020
Remove the reference from handle to the unique/wrapping resource
ReusedHandle as there is meanwhile a strong reference for all async
resources in place via AsyncWarp::resource_.

PR-URL: nodejs#32054
Refs: nodejs#30959
Refs: nodejs#30196
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
targos pushed a commit that referenced this pull request Apr 28, 2020
Remove the reference from handle to the unique/wrapping resource
ReusedHandle as there is meanwhile a strong reference for all async
resources in place via AsyncWarp::resource_.

PR-URL: #32054
Refs: #30959
Refs: #30196
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. domain Issues and PRs related to the domain subsystem. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read property 'enter' of undefined
6 participants