如何解决ldapjs中的ECONNRESET错误



我正在使用LDAP JS。我一次又一次地收到ECONNRESET错误,我也试图浏览它,但没有成功。尝试添加reconnect: true限定符,但没有成功。我的代码和错误如下。

const adConfiguration = {
url: "ldap://" + process.env.ad_URL,
reconnect: true,
tlsOptions: {
rejectUnauthorized: true,
}
}

错误我收到的信息如下:

Waiting for the debugger to disconnect...
events.js:353
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
at TCP.callbackTrampoline (internal/async_hooks.js:134:14)
Emitted 'error' event on Client instance at:
at Socket.onSocketError (F:MFACrypLock_BECrypLockServernode_modulesldapjslibclientclient.js:966:12)
at Socket.emit (events.js:376:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
[nodemon] app crashed - waiting for file changes before starting...

您需要监听ldap客户端实例上的错误并进行处理:

const ldapjs = require('ldapjs')
const adConfiguration = {
url: "ldap://" + process.env.ad_URL,
reconnect: true,
tlsOptions: {
rejectUnauthorized: true,
}
}
const client = ldapjs.createClient(adConfiguration)
client.on('error', (err) => {
console.log(err.message) // this will be your ECONNRESET message
})

我建议在原始ldap客户端周围使用某种抽象,这样当您检测到错误时,就可以适当地重置客户端。

最新更新