zlib: do not leak on destroy#23734
Conversation
|
@mafintosh build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/1283/pipeline |
Sorry, something went wrong.
|
Do you know when this regressed? Or has it always done this? I am wondering if @nodejs/lts will need to backport it. I guess there is no way to unit test this, but a manual test in the PR that could be run by hand while watching sys memory use would help in verifying backports. |
Sorry, something went wrong.
|
@sam-github as far as I can see this have been an issue since Node 8 (previous to that there were no |
Sorry, something went wrong.
|
/to @nodejs/lts |
Sorry, something went wrong.
addaleax
left a comment
There was a problem hiding this comment.
Currently zlib streams will leak their handles if the streams are destroyed using
.destroy(), which means they'll leak when used withstream.pipelineorpumpand an error happens.
That seems somewhat surprising… if it’s true, then this is possibly not a fix for that bug. Even without the extra _close() call here, zlib handles should be weak when not currently performing write operations, so they should be garbage-collected along with the rest of the stream.
Sorry, something went wrong.
|
@addaleax oh interesting, so the _close call is not necessary in general? my leak stats my be off |
Sorry, something went wrong.
|
@mafintosh So… it is not strictly necessary in general, but it will release resources earlier than GC would, which is usually desirable I guess? So, if there are some long-lived references to the zlib stream, that could still be a memory leak – but the fix for that situation might be to not keep those references around, so that GC can do its work? (i.e. this PR is definitely improving things, but you may want to look out for deeper-lying issues.) There might also be a behavioural difference between v8.x and v10.x, at least currently. #21608 made memory allocation reporting for the native zlib handles more accurate, so GC may see lower or higher memory pressure than before. |
Sorry, something went wrong.
|
@addaleax thanks for the explanation, let me see if I can cook up a test case based on that. |
Sorry, something went wrong.
|
(I’m adding |
Sorry, something went wrong.
mcollina
left a comment
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
mcollina
left a comment
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
Sorry, something went wrong.
|
@mafintosh I'll land the async iterators fix as part of the other PR, can you remove it out from this one? |
Sorry, something went wrong.
PR-URL: #23734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: #23734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
|
This lands cleanly on 10.x but requires a backport for 8.x Is it ready to land in LTS yet or does it need a bit more time to bake? |
Sorry, something went wrong.
|
This is ready, but it will need a proper backport. |
Sorry, something went wrong.
PR-URL: #23734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: #23734 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesCurrently zlib streams will leak their handles if the streams are destroyed using
.destroy(), which means they'll leak when used withstream.pipelineorpumpand an error happens.This PR fixes that by implementing
_destroyand call_closeon the handle always.