@autofleet/network 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +17 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -42,12 +42,27 @@ const defaultSettings = {
|
|
|
42
42
|
|
|
43
43
|
const createRequestString = (request) => `[${(request.method || '').toUpperCase()}] ${request.baseURL}${request.url}`;
|
|
44
44
|
|
|
45
|
+
/*
|
|
46
|
+
The default free socket keepalive timeout, in milliseconds.
|
|
47
|
+
Setting to 5000 (5 seconds) as default because out grace period is 10 seconds
|
|
48
|
+
and we want to make sure we don't have any socket issues.
|
|
49
|
+
See https://www.npmjs.com/package/agentkeepalive
|
|
50
|
+
|
|
51
|
+
There is also autoscaling reason for that, if we dont timeout at some point,
|
|
52
|
+
new pods that were auto scaled will not be used.
|
|
53
|
+
*/
|
|
54
|
+
const FREE_SOCKET_TIMEOUT = process.env.FREE_SOCKET_TIMEOUT || 5000;
|
|
55
|
+
|
|
45
56
|
module.exports = class Network {
|
|
46
57
|
constructor(settings = {}) {
|
|
47
58
|
this.settings = merge(defaultSettings, settings);
|
|
48
59
|
if (this.settings.keepAlive) {
|
|
49
|
-
const keepaliveAgent = new Agent(
|
|
50
|
-
|
|
60
|
+
const keepaliveAgent = new Agent({
|
|
61
|
+
freeSocketTimeout: FREE_SOCKET_TIMEOUT,
|
|
62
|
+
});
|
|
63
|
+
const keepaliveHttpsAgent = new HttpsAgent({
|
|
64
|
+
freeSocketTimeout: FREE_SOCKET_TIMEOUT,
|
|
65
|
+
});
|
|
51
66
|
this.settings.httpAgent = keepaliveAgent;
|
|
52
67
|
this.settings.httpsAgent = keepaliveHttpsAgent;
|
|
53
68
|
delete this.settings.keepAlive;
|