Merge pull request #785 from dfit99/master

force socket to be closed on destroy
This commit is contained in:
James Sumners 2022-02-25 15:00:32 -05:00 committed by GitHub
commit e3318a1304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
})
})