diff --git a/lib/client/client.js b/lib/client/client.js index c26ec0e..9caaf84 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -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); diff --git a/test/client.test.js b/test/client.test.js index 7ca4a24..36661e2 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -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(); });