Active directory PassportJS错误:当绑定间歇性未完成时,不能对连接执行其他操作

Active directory PassportJS错误:当绑定间歇性未完成时,不能对连接执行其他操作,active-directory,ldap,passport.js,ldapjs,koa-passport,Active Directory,Ldap,Passport.js,Ldapjs,Koa Passport,TLDR:与或之间是否存在竞争条件问题 我在nodejs应用程序中使用带有passport ldapauth策略的库,用于根据AD(Active Directory)对用户进行身份验证。哇,真是太好了 下面是我从passport.authenticate中得到的错误,我假设它是从LDAP返回的: BusyError:00002024:ldaper:DSID-0C060810,注释:绑定未完成时,不能对连接执行其他操作。 这里的问题很明显,有一个未完成的绑定,必须先关闭它,然后才能进行另一个绑定以

TLDR:与或之间是否存在竞争条件问题

我在nodejs应用程序中使用带有
passport ldapauth
策略的库,用于根据AD(Active Directory)对用户进行身份验证。哇,真是太好了

下面是我从passport.authenticate中得到的错误,我假设它是从LDAP返回的:

BusyError:00002024:ldaper:DSID-0C060810,注释:绑定未完成时,不能对连接执行其他操作。

这里的问题很明显,有一个未完成的绑定,必须先关闭它,然后才能进行另一个绑定以验证下一个用户。解决方案不是这样,它可能是LDAP,也可能是passportjs。我来这里是希望为后者找到解决办法。(在等待对此的响应时,将探索LDAP的配置选项#多处理)

这是我的密码:

import passport from 'koa-passport';
import LdapStrategy from 'passport-ldapauth';
import { readFileSync } from 'fs';
const ldapCert = readFileSync(process.env.LDAP_CERT, 'utf8');

const ldapConfig = {
  server: {
    url: process.env.LDAP_URL,
    bindDN: process.env.LDAP_BINDDN,
    bindCredentials: process.env.LDAP_PASSWORD,
    searchBase: process.env.LDAP_SEARCH_BASE,
    searchFilter: process.env.LDAP_SEARCH_FILTER,
    searchAttributes: ['sAMAccountName'],
    tlsOptions: {
      ca: [ldapCert]
    }
  }
};

module.exports = async (ctx, next) => {
  passport.initialize();
  passport.use(new LdapStrategy(ldapConfig));
  await passport.authenticate('ldapauth', { session: false }, async (err, user, info) => {
    if (err) {
      console.log('Invalid Authentication Error');
      ctx.throw('INVALID_AUTHENTICATION');
    } else if (!user) {
      console.log('Invalid username or password Error');
      ctx.throw('INVALID_USERNAME_PASSWORD');
    } else {
      await next(); // continue to authorization flow
    }
  })(ctx, next);
在开始之前,要知道所有的
ldapconfig
在应用程序的整个生命周期中都保持不变,这意味着我在每次查找时都使用相同的BINDDN和密码

正如标题中所述,这个错误是间歇性发生的。因此,代码本身通常可以正常工作,我可以在95%的时间内对用户进行身份验证,如果密码正确时它抛出
INVALID\u AUTHENTICATION
错误,也就是当我在日志中获取
BusyError

当我输入一个伪造的用户名/密码时,这个问题更加突出,也更容易重现。理想情况下,我应该被提示出现
INVALID\u username\u password
错误,我大约75%的时间都是这样。另外25%我得到
无效的\u身份验证

我甚至尝试使用
ldapsearch
命令工具,结合
tmux
来重现它。我使用相同的binddn同时在20个窗格中运行了一个调用,它们都恢复得很好(我是否应该尝试使用更多的?100?1000?)。这让我相信问题不在于LDAP或AD,而在于passportjs

我的结论是,护照可能存在种族条件问题,但我在互联网上找不到任何文献。有人遇到过这样的事情吗?我相信绑定可能没有关闭,因为有时
passport.authenticate
可能会在调用回调之前返回?这可能吗?这与我如何用async/await编码有关吗

我的退路可能是完全抛弃passportjs,只尝试使用ldapjs。如有任何想法、意见、建议和讨论,将不胜感激

以下是完整的堆栈跟踪(如果需要):

BusyError: 00002024: LdapErr: DSID-0C060810, comment: No other operations may be performed on the connection while a bind is outstanding., data 0, v3839
    at messageCallback (/app/node_modules/ldapjs/lib/client/client.js:1419:45)
    at Parser.onMessage (/app/node_modules/ldapjs/lib/client/client.js:1089:14)
    at emitOne (events.js:116:13)
    at Parser.emit (events.js:211:7)
    at Parser.write (/app/node_modules/ldapjs/lib/messages/parser.js:111:8)
    at TLSSocket.onData (/app/node_modules/ldapjs/lib/client/client.js:1076:22)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:597:20)
InternalServerError: INVALID_AUTHENTICATION
    at Object.throw (/app/node_modules/koa/lib/context.js:97:11)

你明白了吗?你明白了吗?