@@ -22,6 +22,7 @@
|
22 | 22 | 'use strict'; |
23 | 23 | |
24 | 24 | const { |
| 25 | + NumberIsFinite, |
25 | 26 | NumberParseInt, |
26 | 27 | ObjectKeys, |
27 | 28 | ObjectSetPrototypeOf, |
@@ -60,8 +61,6 @@ const kOnKeylog = Symbol('onkeylog');
|
60 | 61 | const kRequestOptions = Symbol('requestOptions'); |
61 | 62 | const kRequestAsyncResource = Symbol('requestAsyncResource'); |
62 | 63 | |
63 | | -// TODO(jazelly): make this configurable |
64 | | -const HTTP_AGENT_KEEP_ALIVE_TIMEOUT_BUFFER = 1000; |
65 | 64 | // New Agent code. |
66 | 65 | |
67 | 66 | // The largest departure from the previous implementation is that |
@@ -114,6 +113,14 @@ function Agent(options) {
|
114 | 113 | this.scheduling = this.options.scheduling || 'lifo'; |
115 | 114 | this.maxTotalSockets = this.options.maxTotalSockets; |
116 | 115 | this.totalSocketCount = 0; |
| 116 | + |
| 117 | +this.agentKeepAliveTimeoutBuffer = |
| 118 | +typeof this.options.agentKeepAliveTimeoutBuffer === 'number' && |
| 119 | +this.options.agentKeepAliveTimeoutBuffer >= 0 && |
| 120 | +NumberIsFinite(this.options.agentKeepAliveTimeoutBuffer) ? |
| 121 | +this.options.agentKeepAliveTimeoutBuffer : |
| 122 | +1000; |
| 123 | + |
117 | 124 | const proxyEnv = this.options.proxyEnv; |
118 | 125 | if (typeof proxyEnv === 'object' && proxyEnv !== null) { |
119 | 126 | this[kProxyConfig] = parseProxyConfigFromEnv(proxyEnv, this.protocol, this.keepAlive); |
@@ -559,7 +566,7 @@ Agent.prototype.keepSocketAlive = function keepSocketAlive(socket) {
|
559 | 566 | if (hint) { |
560 | 567 | // Let the timer expire before the announced timeout to reduce |
561 | 568 | // the likelihood of ECONNRESET errors |
562 | | -let serverHintTimeout = (NumberParseInt(hint) * 1000) - HTTP_AGENT_KEEP_ALIVE_TIMEOUT_BUFFER; |
| 569 | +let serverHintTimeout = (NumberParseInt(hint) * 1000) - this.agentKeepAliveTimeoutBuffer; |
563 | 570 | serverHintTimeout = serverHintTimeout > 0 ? serverHintTimeout : 0; |
564 | 571 | if (serverHintTimeout === 0) { |
565 | 572 | // Cannot safely reuse the socket because the server timeout is |
|