destroy socket if auto-bind fails

This commit is contained in:
Phil Batey 2016-11-22 11:19:59 -07:00
parent cf49ee03f8
commit 5f21dbf4cd
2 changed files with 4 additions and 0 deletions

View File

@ -348,6 +348,9 @@ function Client(options) {
this.on('setup', function (clt, cb) {
clt.bind(options.bindDN, options.bindCredentials, function (err) {
if (err) {
if (self._socket) {
self._socket.destroy()
}
self.emit('error', err);
}
cb(err);

View File

@ -334,6 +334,7 @@ test('auto-bind bad credentials', function (t) {
});
clt.once('error', function (err) {
t.equal(err.code, ldap.LDAP_INVALID_CREDENTIALS);
t.ok(clt._socket.destroyed, 'expect socket to be destroyed');
clt.destroy();
t.end();
});