From 55e6577b750c7c1b6ebb5a13381e7eab7459f85d Mon Sep 17 00:00:00 2001 From: Doowonee Date: Thu, 23 Dec 2021 03:56:14 +0900 Subject: [PATCH] Adding a socket handler for keep TCP connection (#3422) This is not http keepalive option it is TCP level which is lower than HTTP. It will send meanless ack flag packet to server. so it woudn't be drop TCP connection by server side like Firewall, Loadbalancer, Nginx etc. Co-authored-by: Jay --- lib/adapters/http.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index a39773f9f7..98ab7d89a1 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -313,6 +313,12 @@ module.exports = function httpAdapter(config) { reject(enhanceError(err, config, null, req)); }); + // set tcp keep alive to prevent drop connection by peer + req.on('socket', function handleRequestSocket(socket) { + // default interval of sending ack packet is 1 minute + socket.setKeepAlive(true, 1000 * 60); + }); + // Handle request timeout if (config.timeout) { // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.