From 6b59a3604a53a7f85c8392fcb9577aabbd1eb4df Mon Sep 17 00:00:00 2001 From: Ben Botto Date: Tue, 17 Dec 2019 13:54:16 -0800 Subject: [PATCH] Only enables keep-alive on lib-created TCP connections. --- lib/connection.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index b1165b32e1..0ed504d4b1 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -36,6 +36,10 @@ class Connection extends EventEmitter { opts.config.port, opts.config.host ); + + // Enable keep-alive on the socket. It's disabled by default, but the + // user can enable it and supply an initial delay. + this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay); } // if stream is a function, treat it as "stream agent / factory" } else if (typeof opts.config.stream === 'function') { @@ -44,11 +48,6 @@ class Connection extends EventEmitter { this.stream = opts.config.stream; } - // Enable keep-alive on the socket. It's disabled by default, but the - // user can enable it and supply an initial delay. - if (typeof this.stream.setKeepAlive === 'function' && this.config.enableKeepAlive) - this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay); - this._internalId = _connectionId++; this._commands = new Queue(); this._command = null;