Node-ldapjs: problem with "createClient" then "bind" if the connection is slow or unavailable

Created on 17 Feb 2012  路  1Comment  路  Source: ldapjs/node-ldapjs

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:

  • creating the client results in attempt to connect right away: https://github.com/mcavage/node-ldapjs/blob/master/lib/client.js#L147 This sits waiting for the timeout.
  • The I do a bind attempt... which attempts a Client.connect ... which returns right away because 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.

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:

   var client = ldap.createClient({...});
   client.on('connect', function () {
     client.bind( ... );
   });

>All comments

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( ... );
   });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jvanalst picture jvanalst  路  6Comments

lmusat picture lmusat  路  5Comments

abarik1981 picture abarik1981  路  4Comments

atiertant picture atiertant  路  6Comments

SeanPlusPlus picture SeanPlusPlus  路  5Comments