-
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
http: avoid retaining unneeded memory #11926
Conversation
lib/_http_server.js
Outdated
@@ -475,6 +473,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |||
socket.removeListener('data', state.onData); | |||
socket.removeListener('end', state.onEnd); | |||
socket.removeListener('close', state.onClose); | |||
socket.removeAllListeners('drain'); |
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.
I'm not sure if this is ok but there are 2 listeners for the drain
event and both seem to be useless for upgrade requests.
The first checks if _httpMessage
is set and this is never true for upgrade requests.
The second checks if the socket is _paused
but unless I'm missing something this flag is never set for upgrade requests.
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.
.removeAllListeners() also removes any user-installed 'drain' event listeners so no, probably not a good idea.
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.
Yeah I get that but can a user add a listener for the drain
event before this is called?
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.
Yes, server.on('connection', c => c.on('drain', ondrain))
.
4b1709a
to
5c2d743
Compare
/cc @nodejs/http |
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 pending CI
Refs: #11868 |
lib/_http_server.js
Outdated
@@ -475,6 +473,7 @@ function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |||
socket.removeListener('data', state.onData); | |||
socket.removeListener('end', state.onEnd); | |||
socket.removeListener('close', state.onClose); | |||
socket.removeAllListeners('drain'); |
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.
.removeAllListeners() also removes any user-installed 'drain' event listeners so no, probably not a good idea.
5c2d743
to
b435591
Compare
@bnoordhuis updated, PTAL. |
@lpinca You could move it to |
Done, thanks. |
lib/internal/http.js
Outdated
module.exports = { | ||
outHeadersKey: Symbol('outHeadersKey') | ||
outHeadersKey: Symbol('outHeadersKey'), | ||
ondrain |
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.
I'd add a comma, saves one line in the diff next time someone adds a property.
295bd86
to
76b237b
Compare
@lpinca ... this is not landing cleanly for some reason (even tho it shows zero conflicts...) can you please squash the commits, rebase, and I'll try again. |
Prevent the events listeners of the sockets obtained with the HTTP upgrade mechanism from retaining unneeded memory. Refs: nodejs#11868
76b237b
to
0100984
Compare
@jasnell done. |
Prevent the events listeners of the sockets obtained with the HTTP upgrade mechanism from retaining unneeded memory. Ref: #11868 PR-URL: #11926 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Landed in e0a9ad1 |
This will need to be manually backported to v7.x |
Prevent the events listeners of the sockets obtained with the HTTP upgrade mechanism from retaining unneeded memory. Ref: nodejs#11868 PR-URL: nodejs#11926 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
Looks like this change is breaking spdy. Example breakage from spdy tests.
|
@indutny Any chance this could be solved on the spdy side of things? |
Removing the backport-to-v7.x label and adding dont-land-on labels until this is resolved. |
Not sure if the following is the proper way to fix the issue but it seems to work: diff --git a/lib/spdy/server.js b/lib/spdy/server.js
index 777f682..d5321c2 100644
--- a/lib/spdy/server.js
+++ b/lib/spdy/server.js
@@ -189,6 +189,8 @@ proto._onStream = function _onStream (stream) {
socket = new net.Socket(socketOptions)
}
+ socket.server = this;
+
handle.assignSocket(socket)
// For v0.8
Will send a PR. |
That patch seems to not work on Node.js 0.10 and 0.12. The problem is that |
Fixes a regression that caused an error to be thrown when trying to emit the 'timeout' event on the server referenced by `socket.server`. Fixes: nodejs#13435 Refs: nodejs#11926
Fixes a regression that caused an error to be thrown when trying to emit the 'timeout' event on the server referenced by `socket.server`. Fixes: #13435 Refs: #11926 PR-URL: #13578 Reviewed-By: Colin Ihrig <[email protected]>
Fixes a regression that caused an error to be thrown when trying to emit the 'timeout' event on the server referenced by `socket.server`. Fixes: #13435 Refs: #11926 PR-URL: #13578 Reviewed-By: Colin Ihrig <[email protected]>
Prevents the events listeners of the sockets obtained with the HTTP upgrade mechanism from retaining unneeded objects like
state
.Reduces memory usage by ~20%.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)