From ad65c7b1bc6e3617288bdbdd2ffa1341778f3986 Mon Sep 17 00:00:00 2001 From: Konstantin Petryaev Date: Wed, 22 Jun 2016 02:49:41 +0700 Subject: [PATCH] Fix of pool leaking by TCP-keepalive (#918) * fix of bug with pool leaking by TCP keep-alives * add test for check setKeepAlive on connect * fix mistake with var * fix mistake with var --- lib/connection.js | 1 + test/unit/connection/startup-tests.js | 12 ++++++++++++ test/unit/test-helper.js | 2 ++ 3 files changed, 15 insertions(+) diff --git a/lib/connection.js b/lib/connection.js index 44b023cb..2b004d45 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -48,6 +48,7 @@ Connection.prototype.connect = function(port, host) { this.stream.on('connect', function() { self.emit('connect'); + self.stream.setKeepAlive(true); }); this.stream.on('error', function(error) { diff --git a/test/unit/connection/startup-tests.js b/test/unit/connection/startup-tests.js index e3b41991..29212c4e 100644 --- a/test/unit/connection/startup-tests.js +++ b/test/unit/connection/startup-tests.js @@ -43,6 +43,18 @@ test('using closed stream', function() { assert.ok(hit); }); + + test('after stream emits connected event init TCP-keepalive', function() { + + var res = false; + + stream.setKeepAlive = function(bit) { + res = bit; + }; + + assert.ok(stream.emit('connect')); + assert.equal(res, true); + }); }); test('using opened stream', function() { diff --git a/test/unit/test-helper.js b/test/unit/test-helper.js index 3bcd21e0..878898d8 100644 --- a/test/unit/test-helper.js +++ b/test/unit/test-helper.js @@ -15,6 +15,8 @@ p.write = function(packet) { this.packets.push(packet); }; +p.setKeepAlive = function(){}; + p.writable = true; createClient = function() {