-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: client keep-alive for UNIX domain sockets
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 <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
01bee5d
commit 131eef6
Showing
4 changed files
with
57 additions
and
19 deletions.
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
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) | ||
); | ||
} |