vesse/passport-ldapauth

`errorhandler` called twice in strategy.js if LDAP server unreachable

julianlam opened this issue · 1 comments

  • I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions, such as how to use the library, there).
  • I believe this is an issue in this library and not in the underlying libraries ldapjs or ldapauth-fork. (This library is a passport strategy and does not implement the LDAP communication)

Problem Description

I am building an ldap authentication flow for my app and I am encountering a condition where the errorHandler is called twice, leading to the passport.authenticate callback to be called twice.

I believe this is caused by line 274 ldap.once('error', errorHandler);, which proceeds to call ldap.authenticate without ensuring the server connection is valid. Sometimes the errorHandler after // Other errors are (most likely) real errors is called first, sometimes it is called second, so it is a race condition, but they shouldn't ever be called twice anyhow.

Steps to Reproduce

Set up LdapStrategy with url pointing to an unreachable server. In my case, it is a server inside an internal network that I do not have access to. The specific error is ENOTFOUND, so I think putting in any invalid url should work.

passport.authenticate(strategy, async (err, userData, info) => {
  console.log(err);
}

Error will be output twice.

The problem is actual. There is a solution?