Skip to content

Commit

Permalink
Adding a socket handler for keep TCP connection (#3422)
Browse files Browse the repository at this point in the history
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 <jasonsaayman@gmail.com>
  • Loading branch information
doowonee and jasonsaayman committed Dec 22, 2021
1 parent ebedf6b commit 55e6577
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/adapters/http.js
Expand Up @@ -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.
Expand Down

0 comments on commit 55e6577

Please sign in to comment.