https: fix memory leak with https.request()#8647
https: fix memory leak with https.request()#8647imyller wants to merge 1 commit intonodejs:masterfrom
Conversation
43ac439 to
0891876
Compare
lib/_http_agent.js
Outdated
There was a problem hiding this comment.
I'd prefer just using hostHeader.slice() and hostHeader.indexOf(), but if others are not comfortable with that, at the very least the regex should be /:[\s\S]*$/ to match any character (including newlines).
There was a problem hiding this comment.
I left the hostHeader cleanup intentionally unmodified to match the original feature implemented PR #1110
I did not want to fix two unrelated issues in single PR dedicated to memory leak.
There was a problem hiding this comment.
Can you remove the extra blank lines at lines 37, 44, 48, 54, and 56.
There was a problem hiding this comment.
Extra blank lines removed
0891876 to
b6b452c
Compare
|
LGTM |
|
LGTM |
|
FreeBSD CI failed due to force pushed commit New CI run: https://ci.nodejs.org/job/node-test-pull-request/4108/ |
|
I'm going to add lts-agenda label because this leak affects current LTS release too. |
|
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/4127/ |
There was a problem hiding this comment.
I think this line should also be removed? #8647 (comment)
There was a problem hiding this comment.
Thanks. Removed extra line.
If calling `https.request()` with `options.headers.host` defined and `options.servername` undefined, `https.Agent.createSocket` mutates connection `options` after `https.Agent.addRequest` has created empty socket pool array with mismatching connection name. This results in two socket pool arrays being created and only the last one gets eventually deleted by `removeSocket` - causing a memory leak. This commit fixes the leak by making sure that `addRequest` does the same modifications to `options` object as the `createSocket`. `createSocket` is intentionally left unmodified to prevent userland regressions. Test case included. Fixes: nodejs#6687
b6b452c to
4d68ae2
Compare
|
Trying CI again due to the AIX error: https://ci.nodejs.org/job/node-test-pull-request/4179/ |
|
If CI is green, I'll land this. |
|
I'll start landing this:
|
If calling `https.request()` with `options.headers.host` defined and `options.servername` undefined, `https.Agent.createSocket` mutates connection `options` after `https.Agent.addRequest` has created empty socket pool array with mismatching connection name. This results in two socket pool arrays being created and only the last one gets eventually deleted by `removeSocket` - causing a memory leak. This commit fixes the leak by making sure that `addRequest` does the same modifications to `options` object as the `createSocket`. `createSocket` is intentionally left unmodified to prevent userland regressions. Test case included. PR-URL: nodejs#8647 Fixes: nodejs#6687 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jackson Tian <shvyo1987@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
landed in db5a879 |
|
@imyller I'm removing the agenda label for right now as there does not appear to be anything controversial about this change. After it has lived in a release for at least two weeks we can backport |
If calling `https.request()` with `options.headers.host` defined and `options.servername` undefined, `https.Agent.createSocket` mutates connection `options` after `https.Agent.addRequest` has created empty socket pool array with mismatching connection name. This results in two socket pool arrays being created and only the last one gets eventually deleted by `removeSocket` - causing a memory leak. This commit fixes the leak by making sure that `addRequest` does the same modifications to `options` object as the `createSocket`. `createSocket` is intentionally left unmodified to prevent userland regressions. Test case included. PR-URL: #8647 Fixes: #6687 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jackson Tian <shvyo1987@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
If calling `https.request()` with `options.headers.host` defined and `options.servername` undefined, `https.Agent.createSocket` mutates connection `options` after `https.Agent.addRequest` has created empty socket pool array with mismatching connection name. This results in two socket pool arrays being created and only the last one gets eventually deleted by `removeSocket` - causing a memory leak. This commit fixes the leak by making sure that `addRequest` does the same modifications to `options` object as the `createSocket`. `createSocket` is intentionally left unmodified to prevent userland regressions. Test case included. PR-URL: #8647 Fixes: #6687 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jackson Tian <shvyo1987@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Checklist
make -j4 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
https
Description of change
If calling
https.request()withoptions.headers.hostdefined andoptions.servernameundefined,https.Agent.createSocketmutates connectionoptionsafterhttps.Agent.addRequesthas created empty socket pool array with mismatching connection name.This results in two socket pool arrays being created and only the last one gets eventually deleted by
removeSocket- effectively causing a memory leak.This commit fixes the leak by making sure that
addRequestdoes the same modifications tooptionsobject as thecreateSocket.createSocketis intentionally left unmodified to prevent userland regressions.Test case included.
Fixes: #6687
/cc @nodejs/http @nodejs/crypto