force socket to be closed on destroy

This commit is contained in:
Daniel Fiterman 2022-02-10 19:52:48 -05:00 committed by Daniel Fiterman
parent b828515c2e
commit 02077a2779
2 changed files with 24 additions and 1 deletions

View File

@ -776,9 +776,11 @@ Client.prototype.destroy = function destroy (err) {
}) })
if (this.connected) { if (this.connected) {
this.unbind() this.unbind()
} else if (this._socket) { }
if (this._socket) {
this._socket.destroy() this._socket.destroy()
} }
this.emit('destroy', err) this.emit('destroy', err)
} }

View File

@ -1747,3 +1747,24 @@ tap.only('emitError', function (t) {
t.end() 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)
})
})