From d02dbab26dad7b46f989adecd49c84f17bd0a0cd Mon Sep 17 00:00:00 2001 From: hechao <505850765@qq.com> Date: Tue, 6 Jun 2023 19:33:51 +0800 Subject: [PATCH] fix: keepAliveInitialDelay not taking effect --- lib/connection.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/connection.js b/lib/connection.js index 8e861bca8a..2a0214cfad 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -54,7 +54,9 @@ class Connection extends EventEmitter { // Optionally enable keep-alive on the socket. if (this.config.enableKeepAlive) { - this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay); + this.stream.on('connect', () => { + this.stream.setKeepAlive(true, this.config.keepAliveInitialDelay); + }); } // Enable TCP_NODELAY flag. This is needed so that the network packets