Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e3318a1

Browse files
authored
Merge pull request #785 from dfit99/master
force socket to be closed on destroy
2 parents b828515 + 02077a2 commit e3318a1

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/client/client.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,11 @@ Client.prototype.destroy = function destroy (err) {
776776
})
777777
if (this.connected) {
778778
this.unbind()
779-
} else if (this._socket) {
779+
}
780+
if (this._socket) {
780781
this._socket.destroy()
781782
}
783+
782784
this.emit('destroy', err)
783785
}
784786

test/client.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,3 +1747,24 @@ tap.only('emitError', function (t) {
17471747

17481748
t.end()
17491749
})
1750+
1751+
tap.test('socket destroy', function (t) {
1752+
const clt = ldap.createClient({
1753+
socketPath: t.context.socketPath,
1754+
bindDN: BIND_DN,
1755+
bindCredentials: BIND_PW
1756+
})
1757+
1758+
clt.once('connect', function () {
1759+
t.ok(clt)
1760+
clt._socket.once('close', function () {
1761+
t.ok(!clt.connected)
1762+
t.end()
1763+
})
1764+
clt.destroy()
1765+
})
1766+
1767+
clt.once('destroy', function () {
1768+
t.ok(clt.destroyed)
1769+
})
1770+
})

0 commit comments

Comments
 (0)