Socket
Socket
Sign inDemoInstall

agentkeepalive

Package Overview
Dependencies
4
Maintainers
4
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.1.2 to 4.1.3

6

History.md
4.1.3 / 2020-06-15
==================
**fixes**
* [[`4ba9f9c`](http://github.com/node-modules/agentkeepalive/commit/4ba9f9c844f2a6b8037ce56599d25c69ef054d91)] - fix: compatible with node v12.16.3 (#91) (killa <<killa123@126.com>>)
4.1.2 / 2020-04-25

@@ -3,0 +9,0 @@ ==================

57

lib/agent.js

@@ -88,2 +88,12 @@ 'use strict';

this.timeoutSocketCountLastCheck = 0;
this.on('free', socket => {
// https://github.com/nodejs/node/pull/32000
// Node.js native agent will check socket timeout eqs agent.options.timeout.
// Use the ttl or freeSocketTimeout to overwrite.
const timeout = this.calcSocketTimeout(socket);
if (timeout > 0 && socket.timeout !== timeout) {
socket.setTimeout(timeout);
}
});
}

@@ -106,7 +116,8 @@

keepSocketAlive(socket) {
const result = super.keepSocketAlive(socket);
// should not keepAlive, do nothing
if (!result) return result;
calcSocketTimeout(socket) {
/**
* return <= 0: should free socket
* return > 0: should update socket timeout
* return undefined: not find custom timeout
*/
let freeSocketTimeout = this.options.freeSocketTimeout;

@@ -118,14 +129,6 @@ const socketActiveTTL = this.options.socketActiveTTL;

const diff = socketActiveTTL - aliveTime;
// destroy it
if (diff <= 0) {
debug('%s(requests: %s, finished: %s) free but need to destroy by TTL, alive %sms(max %sms)',
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
aliveTime, socketActiveTTL);
return false;
return diff;
}
if (freeSocketTimeout && diff < freeSocketTimeout) {
debug('%s(requests: %s, finished: %s) free and wait for %sms TTL timeout',
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT],
diff);
freeSocketTimeout = diff;

@@ -140,9 +143,23 @@ }

const customFreeSocketTimeout = socket.freeSocketTimeout || socket.freeSocketKeepAliveTimeout;
if (customFreeSocketTimeout && customFreeSocketTimeout < freeSocketTimeout) {
freeSocketTimeout = customFreeSocketTimeout;
}
// FIXME: need to make setRequestSocket as a method on Agent class
// then we can reset the agent.options.timeout when free socket is reused.
socket.setTimeout(freeSocketTimeout);
return customFreeSocketTimeout || freeSocketTimeout;
}
}
keepSocketAlive(socket) {
const result = super.keepSocketAlive(socket);
// should not keepAlive, do nothing
if (!result) return result;
const customTimeout = this.calcSocketTimeout(socket);
if (typeof customTimeout === 'undefined') {
return true;
}
if (customTimeout <= 0) {
debug('%s(requests: %s, finished: %s) free but need to destroy by TTL, request count %s, diff is %s',
socket[SOCKET_NAME], socket[SOCKET_REQUEST_COUNT], socket[SOCKET_REQUEST_FINISHED_COUNT], customTimeout);
return false;
}
if (socket.timeout !== customTimeout) {
socket.setTimeout(customTimeout);
}
return true;

@@ -149,0 +166,0 @@ }

{
"name": "agentkeepalive",
"version": "4.1.2",
"version": "4.1.3",
"description": "Missing keepalive http.Agent",

@@ -62,3 +62,3 @@ "main": "index.js",

},
"version": "8, 10, 12"
"version": "8, 10, 12, 14"
},

@@ -65,0 +65,0 @@ "author": "fengmk2 <fengmk2@gmail.com> (https://fengmk2.com)",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc