-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
http2,tls: store WriteWrap using BaseObjectPtr #35488
Conversation
Create weak `WriteWrap` and `ShutdownWrap` objects, and when referencing them in C++ is necessary, use `BaseObjectPtr<>` instead of plain pointers to keep these objects from being garbage-collected. This solves issues that arise when the underlying `StreamBase` instance is weak, but the `WriteWrap` or `ShutdownWrap` instances are not; in that case, they would otherwise potentially stick around in memory after the stream that they originally belong to is long gone. It probably makes sense to use `BaseObjectptr<>` more extensively in `StreamBase` in the long run as well.
Review requested:
|
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: nodejs#35488 Refs: nodejs#35487 Refs: nodejs#35481
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 78e5875 |
Create weak `WriteWrap` and `ShutdownWrap` objects, and when referencing them in C++ is necessary, use `BaseObjectPtr<>` instead of plain pointers to keep these objects from being garbage-collected. This solves issues that arise when the underlying `StreamBase` instance is weak, but the `WriteWrap` or `ShutdownWrap` instances are not; in that case, they would otherwise potentially stick around in memory after the stream that they originally belong to is long gone. It probably makes sense to use `BaseObjectptr<>` more extensively in `StreamBase` in the long run as well. PR-URL: #35488 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Create weak `WriteWrap` and `ShutdownWrap` objects, and when referencing them in C++ is necessary, use `BaseObjectPtr<>` instead of plain pointers to keep these objects from being garbage-collected. This solves issues that arise when the underlying `StreamBase` instance is weak, but the `WriteWrap` or `ShutdownWrap` instances are not; in that case, they would otherwise potentially stick around in memory after the stream that they originally belong to is long gone. It probably makes sense to use `BaseObjectptr<>` more extensively in `StreamBase` in the long run as well. PR-URL: #35488 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: #35488 Refs: #35487 Refs: #35481 PR-URL: #35490 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
This doesn't land cleanly on 12.x. As 12.x is about to move to maintenance I'm unsure if it makes sense to backport. We could still potentially get this in the 12.20.0 release if it is backported in a timely fashion, but it isn't clear that this is high priority. |
Create weak `WriteWrap` and `ShutdownWrap` objects, and when referencing them in C++ is necessary, use `BaseObjectPtr<>` instead of plain pointers to keep these objects from being garbage-collected. This solves issues that arise when the underlying `StreamBase` instance is weak, but the `WriteWrap` or `ShutdownWrap` instances are not; in that case, they would otherwise potentially stick around in memory after the stream that they originally belong to is long gone. It probably makes sense to use `BaseObjectptr<>` more extensively in `StreamBase` in the long run as well. PR-URL: nodejs#35488 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: nodejs#35488 Refs: nodejs#35487 Refs: nodejs#35481 PR-URL: nodejs#35490 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: nodejs#35488 Refs: nodejs#35487 Refs: nodejs#35481 PR-URL: nodejs#35490 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: #35488 Refs: #35487 Refs: #35481 PR-URL: #35490 Backport-PR-URL: #38786 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
When a process exits cleanly, i.e. because the event loop ends up without things to wait for, the Node.js objects that are left on the heap should be: 1. weak, i.e. ready for garbage collection once no longer referenced, or 2. detached, i.e. scheduled for destruction once no longer referenced, or 3. an unrefed libuv handle, i.e. does not keep the event loop alive, or 4. an inactive libuv handle (essentially the same here) There are a few exceptions to this rule, but generally, if there are C++-backed Node.js objects on the heap that do not fall into the above categories, we may be looking at a potential memory leak. Most likely, the cause is a missing `MakeWeak()` call on the corresponding object. In order to avoid this kind of problem, we check the list of BaseObjects for these criteria. In this commit, we only do so when explicitly instructed to or when in debug mode (where --verify-base-objects is always-on). In particular, this avoids the kinds of memory leak issues that were fixed in the PRs referenced below. Refs: #35488 Refs: #35487 Refs: #35481 PR-URL: #35490 Backport-PR-URL: #38786 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
Create weak
WriteWrap
andShutdownWrap
objects, and whenreferencing them in C++ is necessary, use
BaseObjectPtr<>
instead of plain pointers to keep these objects from being
garbage-collected.
This solves issues that arise when the underlying
StreamBase
instance is weak, but the
WriteWrap
orShutdownWrap
instancesare not; in that case, they would otherwise potentially stick
around in memory after the stream that they originally belong
to is long gone.
It probably makes sense to use
BaseObjectptr<>
more extensivelyin
StreamBase
in the long run as well.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes