Asad Mehmood
Asad Mehmood

Reputation: 342

how to resolve ECONNRESET error in ldapjs?

I am working with LDAP JS. I am receiving ECONNRESET Error again and again, I also tried to browse it but no success. tried to add reconnect: true qualifier but no success. my code and error is as follows.

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

Error I am receiving is as follows:

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:\MFA\CrypLock_BE\CrypLockServer\node_modules\ldapjs\lib\client\client.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...

Upvotes: 2

Views: 2859

Answers (1)

Joel Driver
Joel Driver

Reputation: 31

You need to listen for the error on your ldap client instance and handle it:

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
})

I recommend using some sort of abstraction around your raw ldap client so when you detect the error you can reset your client appropriately.

Upvotes: 3

Related Questions