-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: client keep-alive for UNIX domain sockets #13214
Conversation
semver-major? It seems that keep-alive was skipped on purpose when using UNIX domain sockets. |
lib/_http_client.js
Outdated
@@ -274,7 +259,7 @@ function ClientRequest(options, cb) { | |||
this._last = true; | |||
this.shouldKeepAlive = false; | |||
if (typeof options.createConnection === 'function') { | |||
newSocket = options.createConnection(options, oncreate); | |||
var newSocket = options.createConnection(options, oncreate); |
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.
If it's initialized, never re-assigned, scope limited, and quacks like a duck; it's const
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.
Good call! I left it as var
as it had already been that on line 244 previously, but const
is more appropriate here now.
var newSocket; | ||
if (this.socketPath) { | ||
this._last = true; | ||
this.shouldKeepAlive = false; |
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.
@bnoordhuis I tried to do a deep blame, seems like it's your code
Line 1025 in bc7cfd7
self.shouldKeepAlive = false; |
Is there a specific reason why POSIX sockets
shouldKeepAlive = false
?
this could be viewed as semver-minor, not major, in that it's adding support for something that didn't work previously. |
That works for me. |
http.get({ | ||
socketPath: common.PIPE, | ||
headers: {connection: 'keep-alive'} | ||
}, (res) => res.on('data', () => {}).on('error', assert.fail).on('end', cb)); |
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.
Nit: Instead of .on('data', () => {})
, use .on('data', common.mustNotCall())
to make it clear that the expectation is that the handler will never execute in this test.
asyncLoop(makeKeepAliveRequest, 10, () => | ||
server.getConnections(common.mustCall((err, conns) => { | ||
assert.ifError(err); | ||
assert.strictEqual(1, conns); |
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.
Nit: can you please swap the arguments?
|
||
function asyncLoop(fn, times, cb) { | ||
fn(function handler() { | ||
if (--times) { |
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.
Nit: if I'm not wrong this should be times--
.
@@ -130,6 +130,9 @@ Agent.prototype.getName = function getName(options) { | |||
if (options.family === 4 || options.family === 6) | |||
name += ':' + options.family; | |||
|
|||
if (options.socketPath) | |||
name += ':' + options.socketPath; |
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 think it makes sense to extend test/parallel/test-http-agent-getname.js
and cover 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.
Nit: the socketPath should not be set when a family, a port or a localAddress is set. Therefore it would be nicer branch wise to write
if (options.socketPath) {
name += `:::${options.socketPath}`;
} else {
if (options.port)
// ...
if (options.localAddress)
// ...
// ...
}
I think it is similar with servername
down below.
|
||
common.refreshTmpDir(); | ||
|
||
server.listen(common.PIPE, () => |
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.
common.mustCall()
on these?
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.
There's a common.mustCall()
at the callback that's actually making assertions, and in order to get there, this callback needs to be called, so I think it's implied. (Or, is there a best-test-practice for this stating all callbacks should have a mustCall()
?)
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.
(Or, is there a best-test-practice for this stating all callbacks should have a mustCall()?)
Nah, it's a matter of judgment. There are certainly callbacks that should not be wrapped (such as callbacks in cluster workers, which will throw but be ignored by the cluster master, so having them wrapped gives a false sense of security that the callback is being executed).
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 guess I'll put them in anyway to be super clear that these are all expected to run.
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.
Needs a rebase and I have a nit but it should not block this from landing. Otherwise LGTM
@@ -130,6 +130,9 @@ Agent.prototype.getName = function getName(options) { | |||
if (options.family === 4 || options.family === 6) | |||
name += ':' + options.family; | |||
|
|||
if (options.socketPath) | |||
name += ':' + options.socketPath; |
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.
Nit: the socketPath should not be set when a family, a port or a localAddress is set. Therefore it would be nicer branch wise to write
if (options.socketPath) {
name += `:::${options.socketPath}`;
} else {
if (options.port)
// ...
if (options.localAddress)
// ...
// ...
}
I think it is similar with servername
down below.
Hey folks! Sorry, I'm going to close this one for now. I'd tried rebasing it, and when I do, it exposes issues with |
You could just add the blocked label and reopen now? |
@BridgeAR Oh! That hadn't occurred to me. Thanks for pointing out that I could do that. |
As the other PR should land today, this should be rebased. |
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets.
d41b431
to
2da5453
Compare
Rebased. New CI: https://ci.nodejs.org/job/node-test-pull-request/10213/ |
Just a quick call-out to @nodejs/http and @bnoordhuis for review. I think unless there's any objections, I'll probably land this early next week. |
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: #13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Ping @bengl |
Landed as 2043944. |
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: nodejs#13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
`Connection: keep-alive` is now properly supported when making client connections to UNIX domain sockets so `request.abort()` should not blindly destroy the underlying socket. Refs: nodejs#13214 (comment)
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: #13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: nodejs/node#13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: #13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Makes `Connection: keep-alive` behave correctly when making client connections to UNIX domain sockets. Prior to this, connections would never be re-used, but the keep-alive would cause the connections to stick around until they time out. This would lead to an eventual EMFILE error due to all the connections staying open. This was due to http.Agent not properly supporting UNIX domain sockets. PR-URL: #13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Should this be backported to |
@MylesBorins this depends on #14564, which is marked |
`Connection: keep-alive` is now properly supported when making client connections to UNIX domain sockets so `request.abort()` should not blindly destroy the underlying socket. PR-URL: #15650 Refs: #13214 (comment) Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
`Connection: keep-alive` is now properly supported when making client connections to UNIX domain sockets so `request.abort()` should not blindly destroy the underlying socket. PR-URL: #15650 Refs: #13214 (comment) Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
`Connection: keep-alive` is now properly supported when making client connections to UNIX domain sockets so `request.abort()` should not blindly destroy the underlying socket. PR-URL: nodejs/node#15650 Refs: nodejs/node#13214 (comment) Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
`Connection: keep-alive` is now properly supported when making client connections to UNIX domain sockets so `request.abort()` should not blindly destroy the underlying socket. PR-URL: nodejs/node#15650 Refs: nodejs/node#13214 (comment) Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Makes
Connection: keep-alive
behave correctly when making clientconnections to UNIX domain sockets.
Prior to this, connections would never be re-used, but the keep-alive
would cause the connections to stick around until they time out. This
would lead to an eventual EMFILE error due to all the connections
staying open. This was due to http.Agent not properly supporting UNIX
domain sockets.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
http, test