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) + }) +})