Bad event handling, and working with node 0.8
This commit is contained in:
parent
fd9d713cdc
commit
0da050009b
|
@ -105,7 +105,10 @@ function setupSocket(socket, opts) {
|
||||||
// On close we have to walk the outstanding messages and go invoke their
|
// On close we have to walk the outstanding messages and go invoke their
|
||||||
// callback with an error
|
// callback with an error
|
||||||
socket.on('close', function onClose(had_err) {
|
socket.on('close', function onClose(had_err) {
|
||||||
|
socket.removeAllListeners('connect');
|
||||||
|
socket.removeAllListeners('close');
|
||||||
socket.removeAllListeners('data');
|
socket.removeAllListeners('data');
|
||||||
|
socket.removeAllListeners('drain');
|
||||||
socket.removeAllListeners('end');
|
socket.removeAllListeners('end');
|
||||||
socket.removeAllListeners('error');
|
socket.removeAllListeners('error');
|
||||||
socket.removeAllListeners('timeout');
|
socket.removeAllListeners('timeout');
|
||||||
|
@ -700,7 +703,9 @@ Client.prototype._connect = function _connect() {
|
||||||
var socket = null;
|
var socket = null;
|
||||||
var timer = false;
|
var timer = false;
|
||||||
|
|
||||||
function onConnect() {
|
socket = proto.connect((this.port || this.socketPath), this.host);
|
||||||
|
|
||||||
|
socket.once('connect', function onConnect() {
|
||||||
if (timer)
|
if (timer)
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
|
||||||
|
@ -709,24 +714,21 @@ Client.prototype._connect = function _connect() {
|
||||||
socket.ldap.id = nextClientId() + '__' + socket.ldap.id;
|
socket.ldap.id = nextClientId() + '__' + socket.ldap.id;
|
||||||
self.log = self.log.child({ldap_id: socket.ldap.id}, true);
|
self.log = self.log.child({ldap_id: socket.ldap.id}, true);
|
||||||
|
|
||||||
if (log.trace())
|
log.trace('connect event');
|
||||||
log.trace('connect event');
|
|
||||||
|
|
||||||
self.socket = socket;
|
self.socket = socket;
|
||||||
self.emit('connect', socket);
|
self.emit('connect', socket);
|
||||||
}
|
});
|
||||||
|
|
||||||
socket = proto.connect((this.port || this.socketPath),
|
|
||||||
(this.host ? this.host : onConnect),
|
|
||||||
(this.host ? onConnect : undefined));
|
|
||||||
|
|
||||||
setupSocket(socket, this);
|
setupSocket(socket, this);
|
||||||
|
|
||||||
if (this.connectTimeout) {
|
if (this.connectTimeout) {
|
||||||
timer = setTimeout(function onConnectTimeout() {
|
timer = setTimeout(function onConnectTimeout() {
|
||||||
socket.destroy();
|
if (!socket || !socket.readable || !socket.writeable) {
|
||||||
|
socket.destroy();
|
||||||
|
|
||||||
self.emit('connectTimeout');
|
self.emit('connectTimeout');
|
||||||
|
}
|
||||||
}, this.connectTimeout);
|
}, this.connectTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,8 @@ LDAPResult.prototype.end = function (status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.log.warn('%s failure to write message %j: %s',
|
this.log.warn(e, '%s failure to write message %j',
|
||||||
this.connection.ldap.id, this.json, e.toString());
|
this.connection.ldap.id, this.json);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -108,13 +108,13 @@ SearchResponse.prototype.send = function (entry, nofiltering) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore attributes
|
// Restore attributes
|
||||||
Object.keys(savedAttrs).forEach(function (k) {
|
Object.keys(savedAttrs || {}).forEach(function (k) {
|
||||||
save.attributes[k] = savedAttrs[k];
|
save.attributes[k] = savedAttrs[k];
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.log.warn('%s failure to write message %j: %s',
|
this.log.warn(e, '%s failure to write message %j',
|
||||||
this.connection.ldap.id, this.json, e.toString());
|
this.connection.ldap.id, this.json);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
"name": "ldapjs",
|
"name": "ldapjs",
|
||||||
"homepage": "http://ldapjs.org",
|
"homepage": "http://ldapjs.org",
|
||||||
"description": "LDAP client and server APIs",
|
"description": "LDAP client and server APIs",
|
||||||
"version": "0.5.1",
|
"version": "0.5.2",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/mcavage/node-ldapjs.git"
|
"url": "git://github.com/mcavage/node-ldapjs.git"
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
"lib": "./lib"
|
"lib": "./lib"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "~0.6"
|
"node": ">=0.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asn1": "0.1.11",
|
"asn1": "0.1.11",
|
||||||
|
|
|
@ -130,15 +130,16 @@ test('setup', function (t) {
|
||||||
|
|
||||||
server.listen(SOCKET, function () {
|
server.listen(SOCKET, function () {
|
||||||
client = ldap.createClient({
|
client = ldap.createClient({
|
||||||
connectTimeout: 100,
|
connectTimeout: parseInt(process.env.LDAP_CONNECT_TIMEOUT || 0, 10),
|
||||||
socketPath: SOCKET,
|
socketPath: SOCKET,
|
||||||
maxConnections: process.env.LDAP_MAX_CONNS || 5,
|
maxConnections: parseInt(process.env.LDAP_MAX_CONNS || 5, 10),
|
||||||
idleTimeoutMillis: 10,
|
idleTimeoutMillis: 10,
|
||||||
log: new Logger({
|
log: new Logger({
|
||||||
name: 'ldapjs_unit_test',
|
name: 'ldapjs_unit_test',
|
||||||
stream: process.stderr,
|
stream: process.stderr,
|
||||||
level: (process.env.LOG_LEVEL || 'info'),
|
level: (process.env.LOG_LEVEL || 'info'),
|
||||||
serializers: Logger.stdSerializers
|
serializers: Logger.stdSerializers,
|
||||||
|
src: true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
t.ok(client);
|
t.ok(client);
|
||||||
|
@ -149,7 +150,6 @@ test('setup', function (t) {
|
||||||
|
|
||||||
|
|
||||||
test('simple bind failure', function (t) {
|
test('simple bind failure', function (t) {
|
||||||
try {
|
|
||||||
client.bind(BIND_DN, uuid(), function (err, res) {
|
client.bind(BIND_DN, uuid(), function (err, res) {
|
||||||
t.ok(err);
|
t.ok(err);
|
||||||
t.notOk(res);
|
t.notOk(res);
|
||||||
|
@ -162,10 +162,6 @@ test('simple bind failure', function (t) {
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
console.log(e.stack);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue