-
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: client keep-alive for UNIX domain sockets #13214
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -240,23 +240,7 @@ function ClientRequest(options, cb) { | |||
this._deferToConnect(null, null, () => this._flush()); | ||||
}; | ||||
|
||||
var newSocket; | ||||
if (this.socketPath) { | ||||
this._last = true; | ||||
this.shouldKeepAlive = false; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Is there a specific reason why POSIX sockets shouldKeepAlive = false ?
|
||||
var optionsPath = { | ||||
path: this.socketPath, | ||||
timeout: this.timeout, | ||||
rejectUnauthorized: !!options.rejectUnauthorized | ||||
}; | ||||
newSocket = this.agent.createConnection(optionsPath, oncreate); | ||||
if (newSocket && !called) { | ||||
called = true; | ||||
this.onSocket(newSocket); | ||||
} else { | ||||
return; | ||||
} | ||||
} else if (this.agent) { | ||||
if (this.agent) { | ||||
// If there is an agent we should default to Connection:keep-alive, | ||||
// but only if the Agent will actually reuse the connection! | ||||
// If it's not a keepAlive agent, and the maxSockets==Infinity, then | ||||
|
@@ -274,7 +258,7 @@ function ClientRequest(options, cb) { | |||
this._last = true; | ||||
this.shouldKeepAlive = false; | ||||
if (typeof options.createConnection === 'function') { | ||||
newSocket = options.createConnection(options, oncreate); | ||||
const newSocket = options.createConnection(options, oncreate); | ||||
if (newSocket && !called) { | ||||
called = true; | ||||
this.onSocket(newSocket); | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer((req, res) => res.end()); | ||
|
||
common.refreshTmpDir(); | ||
|
||
server.listen(common.PIPE, common.mustCall(() => | ||
asyncLoop(makeKeepAliveRequest, 10, common.mustCall(() => | ||
server.getConnections(common.mustCall((err, conns) => { | ||
assert.ifError(err); | ||
assert.strictEqual(conns, 1); | ||
server.close(); | ||
})) | ||
)) | ||
)); | ||
|
||
function asyncLoop(fn, times, cb) { | ||
fn(function handler() { | ||
if (--times) { | ||
fn(handler); | ||
} else { | ||
cb(); | ||
} | ||
}); | ||
} | ||
function makeKeepAliveRequest(cb) { | ||
http.get({ | ||
socketPath: common.PIPE, | ||
headers: { connection: 'keep-alive' } | ||
}, (res) => res.on('data', common.mustNotCall()) | ||
.on('error', assert.fail) | ||
.on('end', cb) | ||
); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
I think it is similar with
servername
down below.