|
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 | constkRequestOptions=Symbol('requestOptions'); |
61 | 62 | constkRequestAsyncResource=Symbol('requestAsyncResource'); |
62 | 63 |
|
63 | | -// TODO(jazelly): make this configurable |
64 | | -constHTTP_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 | +typeofthis.options.agentKeepAliveTimeoutBuffer==='number'&& |
| 119 | +this.options.agentKeepAliveTimeoutBuffer>=0&& |
| 120 | +NumberIsFinite(this.options.agentKeepAliveTimeoutBuffer) ? |
| 121 | +this.options.agentKeepAliveTimeoutBuffer : |
| 122 | +1000; |
| 123 | + |
117 | 124 | constproxyEnv=this.options.proxyEnv; |
118 | 125 | if(typeofproxyEnv==='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 | | -letserverHintTimeout=(NumberParseInt(hint)*1000)-HTTP_AGENT_KEEP_ALIVE_TIMEOUT_BUFFER; |
| 569 | +letserverHintTimeout=(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 |
|
0 commit comments