aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBryan English <bryan@bryanenglish.com>2017-05-25 00:32:04 -0700
committerBryan English <bryan@bryanenglish.com>2017-09-27 18:31:17 -0700
commit2043944a4c62de60e7a04e8c914b565114c4b11b (patch)
tree8968545721889a1b539057b9b60576da60341a1a /lib
parent510cab7a3d12ee95e0b04f9682c07d0d8a8d84a5 (diff)
downloadandroid-node-v8-2043944a4c62de60e7a04e8c914b565114c4b11b.tar.gz
android-node-v8-2043944a4c62de60e7a04e8c914b565114c4b11b.tar.bz2
android-node-v8-2043944a4c62de60e7a04e8c914b565114c4b11b.zip
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: https://github.com/nodejs/node/pull/13214 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/_http_agent.js7
-rw-r--r--lib/_http_client.js20
2 files changed, 9 insertions, 18 deletions
diff --git a/lib/_http_agent.js b/lib/_http_agent.js
index ddd36c158e..e71f0cb441 100644
--- a/lib/_http_agent.js
+++ b/lib/_http_agent.js
@@ -131,6 +131,9 @@ Agent.prototype.getName = function getName(options) {
if (options.family === 4 || options.family === 6)
name += ':' + options.family;
+ if (options.socketPath)
+ name += ':' + options.socketPath;
+
return name;
};
@@ -147,6 +150,8 @@ Agent.prototype.addRequest = function addRequest(req, options, port/*legacy*/,
options = util._extend({}, options);
util._extend(options, this.options);
+ if (options.socketPath)
+ options.path = options.socketPath;
if (!options.servername) {
options.servername = options.host;
@@ -199,6 +204,8 @@ Agent.prototype.createSocket = function createSocket(req, options, cb) {
var self = this;
options = util._extend({}, options);
util._extend(options, self.options);
+ if (options.socketPath)
+ options.path = options.socketPath;
if (!options.servername) {
options.servername = options.host;
diff --git a/lib/_http_client.js b/lib/_http_client.js
index a0e4fb2507..6eb7d34fc5 100644
--- a/lib/_http_client.js
+++ b/lib/_http_client.js
@@ -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;
- 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);