From 02077a277931640d14a5e68781cff328c84d2f4e Mon Sep 17 00:00:00 2001 From: Daniel Fiterman Date: Thu, 10 Feb 2022 19:52:48 -0500 Subject: [PATCH] force socket to be closed on destroy --- lib/client/client.js | 4 +++- test/client.test.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/client/client.js b/lib/client/client.js index 9d5a638..7d74aa7 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -776,9 +776,11 @@ Client.prototype.destroy = function destroy (err) { }) if (this.connected) { this.unbind() - } else if (this._socket) { + } + if (this._socket) { this._socket.destroy() } + this.emit('destroy', err) } diff --git a/test/client.test.js b/test/client.test.js index 14b5dd5..0559f64 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -1747,3 +1747,24 @@ tap.only('emitError', function (t) { t.end() }) + +tap.test('socket destroy', function (t) { + const clt = ldap.createClient({ + socketPath: t.context.socketPath, + bindDN: BIND_DN, + bindCredentials: BIND_PW + }) + + clt.once('connect', function () { + t.ok(clt) + clt._socket.once('close', function () { + t.ok(!clt.connected) + t.end() + }) + clt.destroy() + }) + + clt.once('destroy', function () { + t.ok(clt.destroyed) + }) +})