From 3b101a7b2face4d4318c9cf0def05ef6b1805cca Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Tue, 24 Jun 2014 05:33:19 -0500 Subject: [PATCH] Cease reconnection when client.destroy is called --- lib/client/client.js | 5 +++++ test/client.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/client/client.js b/lib/client/client.js index bf0e32e..1e3ae8b 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -686,6 +686,7 @@ Client.prototype.destroy = function destroy() { }); } this.unbind(); + this.emit('destroy'); }; @@ -919,6 +920,10 @@ Client.prototype._connect = function _connect() { } this.connecting = true; retry.start(); + // Abbord reconnection attemps if client is destroyed + this.on('destroy', function () { + retry.abort(); + }); }; /** diff --git a/test/client.test.js b/test/client.test.js index e049614..aa350c1 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -618,6 +618,34 @@ test('idle timeout', function (t) { }); +test('abort reconnect', function (t) { + var abortClient = ldap.createClient({ + connectTimeout: parseInt(process.env.LDAP_CONNECT_TIMEOUT || 0, 10), + socketPath: '/dev/null', + reconnect: {}, + log: new Logger({ + name: 'ldapjs_unit_test', + stream: process.stderr, + level: (process.env.LOG_LEVEL || 'info'), + serializers: Logger.stdSerializers, + src: true + }) + }); + var retryCount = 0; + abortClient.on('connectError', function () { + ++retryCount; + }); + abortClient.once('connectError', function () { + t.ok(true); + abortClient.once('destroy', function () { + t.ok(retryCount < 3); + t.end(); + }); + abortClient.destroy(); + }); +}); + + test('abandon (GH-27)', function (t) { client.abandon(401876543, function (err) { t.ifError(err);