question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client.bind() should not pass an error to the callback function before having tried to connect to all server urls

See original GitHub issue

First, thanks for the great library! Also very cool that multiple server urls are supported now. Regarding this I ran into a problem.

I use the following code:

this.client.bind(
  this.activeDirectoryConfig.username,
  this.activeDirectoryConfig.password,
  (error) => {
    if (error) {
      sharedLogger.error(
        `Error in ActiveDirectoryClient.bindServiceUser() - ${error}`
      );
      reject(error);
    } else {
      resolve();
    }
  }
);

In case the client can not connect to the first server url in the array, the callback is called with an error. Later, when attempting to connect to the second server url, the callback is called again, this time without an error.

In my opinion the callback should not be called with an error before all server urls have been tried. Only if all attempts have failed, an error should be thrown.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jsumnerscommented, Dec 13, 2020

I think this is something we just plain forgot to address in https://github.com/ldapjs/node-ldapjs/pull/658

I am okay with a PR that:

  1. Recognizes an array has been passed for the server list
  2. In the case of the array list, tries each server until one succeeds or all fail
  3. If all fail returns an error like:
{
  message: 'could not connect to any specified servers',
  details: [
    { message: 'cause for server connection failure', serverAddress: 'tried.one.example.com' },
    { message: 'cause for server connection failure', serverAddress: 'tried.two.example.com' }
  ]
}
0reactions
gizmoduscommented, Dec 10, 2020

I would only emit one error. This error could be a summary of all failed connection attempts:

“Error: Connection to ldap servers failed: [error of connection attempt to first server], [error of connection attempt to second server] …”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding Callback function in NodeJS - Stack Overflow
I am very new to Node Js and Concept of Callback Mechanism , I have working code to authenticate the User based on...
Read more >
ldapjs Client API
Unbinding results in disconnecting the client regardless of whether a bind operation was performed. The callback argument is optional as unbind does not...
Read more >
Paho Python MQTT Client - Working with Connections
A look at client connections and the Paho MQTT client. ... Create callback function on_connect(); Bind callback to callback function ...
Read more >
Azure Functions error handling and retry guidance
Learn to handle errors and retry events in Azure Functions with links to specific binding errors, including information on retry policies.
Read more >
Error handling in Node.js - LogRocket Blog
Deliver reliable software by learning how to handle errors in Node.js using callbacks, promises, and event emitters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found