-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Conversation
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
// 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; |
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 it ok that on second reuse of the handle
the binding to the first ReusedHandle
is removed?
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.
@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
Thanks for fixing this! But it seems that the use of AsyncHooks by domains is in general risky as there might be other users not using an |
@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… |
@nodejs/domains @nodejs/async_hooks |
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.
LGTM
Landed in d26a74d |
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 Hello and thank you from Sentry 👋 😄 🎉 |
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
If
asyncReset()
is used to specify an alternative resource objectto 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), orvcbuild test
(Windows) passesFYI @Flarna