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