I have this code:
var server = ldap.createClient({
url: config.ufds.url
});
try {
server.bind(config.ldap.rootDn, config.ldap.password, function(err) {
if (err) {
console.log("XXX error binding to LDAP", err)
return callback(err);
}
console.log("XXX here")
var app;
try {
app = new App(config, server, log);
} catch(err) {
return callback(err);
}
return callback(null, app);
});
} catch(e) {
console.log("XXX boom:", e)
}
... and I _don't_ have a LDAP server running at the configured url. The undesired result is that my callback to bind returns before there is a connection. Either my app hangs there or exits quickly.
Digging through ldapjs' client.js a bit (ldapjs version 0.4.8, the latest), it looks like:
this.connection is set ... which then attempts a BindRequest (https://github.com/mcavage/node-ldapjs/blob/master/lib/client.js#L238)... after which I'm not really sure what is happening.
Naively I'd say the automatic attempt to connect in the Client constructor should be removed.
What I resolved this down to is keeping the connect() in the constructor, but stopping all the magic of trying to deal with an unavailable socket. The new paradigm (in an 0.5 branch) will be like:
var client = ldap.createClient({...});
client.on('connect', function () {
client.bind( ... );
});
Most helpful comment
What I resolved this down to is keeping the
connect()in the constructor, but stopping all the magic of trying to deal with an unavailable socket. The new paradigm (in an 0.5 branch) will be like: