From 6e36baa1e44e6bb9198e14f5eb08b0cb17188758 Mon Sep 17 00:00:00 2001 From: NumminorihSF Date: Thu, 14 Jan 2016 14:04:24 +0700 Subject: [PATCH 1/4] fix of bug with pool leaking by TCP keep-alives --- lib/connection.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/connection.js b/lib/connection.js index f606de136..810037310 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) { From c32ad2ff3ecd1e25214c155dd32627d55d48c106 Mon Sep 17 00:00:00 2001 From: NumminorihSF Date: Thu, 14 Jan 2016 14:39:29 +0700 Subject: [PATCH 2/4] add test for check setKeepAlive on connect --- test/unit/connection/startup-tests.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/unit/connection/startup-tests.js b/test/unit/connection/startup-tests.js index e3b419917..7955be602 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; + + con.setKeepAlive = function(bit) { + res = bit; + }; + + assert.ok(stream.emit('connect')); + assert.equal(res, true); + }); }); test('using opened stream', function() { From 4566fec2db8c5c3aac261b7d5ee16efff4739405 Mon Sep 17 00:00:00 2001 From: NumminorihSF Date: Thu, 14 Jan 2016 14:41:04 +0700 Subject: [PATCH 3/4] fix mistake with var --- test/unit/connection/startup-tests.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/connection/startup-tests.js b/test/unit/connection/startup-tests.js index 7955be602..29212c4ee 100644 --- a/test/unit/connection/startup-tests.js +++ b/test/unit/connection/startup-tests.js @@ -48,7 +48,7 @@ test('using closed stream', function() { var res = false; - con.setKeepAlive = function(bit) { + stream.setKeepAlive = function(bit) { res = bit; }; From a6bf98fc8f6cab765cc31272d181c084a8cd1ae1 Mon Sep 17 00:00:00 2001 From: NumminorihSF Date: Thu, 14 Jan 2016 14:43:07 +0700 Subject: [PATCH 4/4] fix mistake with var --- test/unit/test-helper.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/test-helper.js b/test/unit/test-helper.js index 3bcd21e04..878898d8b 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() {