Merge client-pool-events from pfmooney/node-ldapjs
Fix mcavage/node-ldapjs#87
This commit is contained in:
commit
dfbb6031c6
|
@ -164,6 +164,11 @@ function setupSocket(socket, opts) {
|
|||
if (log.trace())
|
||||
log.trace({err: err}, 'error event: %s', new Error().stack);
|
||||
|
||||
if (opts.connectTimer) {
|
||||
clearTimeout(opts.connectTimer);
|
||||
opts.connectTimer = false;
|
||||
}
|
||||
|
||||
if (opts.listeners('error').length)
|
||||
opts.emit('error', err);
|
||||
|
||||
|
@ -706,11 +711,11 @@ Client.prototype._connect = function _connect() {
|
|||
var proto = this.secure ? tls : net;
|
||||
var self = this;
|
||||
var socket = null;
|
||||
var timer = false;
|
||||
this.connectTimer = false;
|
||||
|
||||
function onConnect() {
|
||||
if (timer)
|
||||
clearTimeout(timer);
|
||||
if (self.connectTimer)
|
||||
clearTimeout(self.connectTimer);
|
||||
|
||||
socket.removeListener('connect', onConnect);
|
||||
socket.removeListener('secureConnect', onConnect);
|
||||
|
@ -734,7 +739,7 @@ Client.prototype._connect = function _connect() {
|
|||
setupSocket(socket, this);
|
||||
|
||||
if (this.connectTimeout) {
|
||||
timer = setTimeout(function onConnectTimeout() {
|
||||
this.connectTimer = setTimeout(function onConnectTimeout() {
|
||||
if (!socket || !socket.readable || !socket.writeable) {
|
||||
socket.destroy();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ var RETURN_VAL_OPS = [
|
|||
|
||||
///--- Internal Functions
|
||||
|
||||
function createPool(options) {
|
||||
function createPool(options, clientpool) {
|
||||
assert.ok(options);
|
||||
|
||||
return pooling.createPool({
|
||||
|
@ -46,9 +46,16 @@ function createPool(options) {
|
|||
|
||||
client.on('error', function (err) {
|
||||
client.removeAllListeners('connect');
|
||||
client.removeAllListeners('connectTimeout');
|
||||
clientpool.emit('error', err);
|
||||
return callback(err);
|
||||
});
|
||||
|
||||
client.on('connectTimeout', function () {
|
||||
client.removeAllListeners('connect');
|
||||
clientpool.emit('connectTimeout');
|
||||
});
|
||||
|
||||
client.once('connect', function onConnect() {
|
||||
client.removeAllListeners('error');
|
||||
|
||||
|
@ -118,7 +125,7 @@ function ClientPool(options) {
|
|||
url: options.url,
|
||||
tlsOptions: options.tlsOptions
|
||||
};
|
||||
this.pool = createPool(options);
|
||||
this.pool = createPool(options, this);
|
||||
}
|
||||
util.inherits(ClientPool, EventEmitter);
|
||||
module.exports = ClientPool;
|
||||
|
@ -241,7 +248,7 @@ ClientPool.prototype.bind = function bind(dn, creds, controls, callback) {
|
|||
self.options.bindControls = null;
|
||||
|
||||
return this.pool.shutdown(function () {
|
||||
self.pool = createPool(self.options);
|
||||
self.pool = createPool(self.options, self);
|
||||
|
||||
return self.pool.acquire(function onAcquire(err, client) {
|
||||
if (err)
|
||||
|
|
Loading…
Reference in New Issue