Node-ldapjs: How to gracefully close connection to the server (as a client)?

Created on 15 Jun 2016  路  9Comments  路  Source: ldapjs/node-ldapjs

I'm using ldapjs as a client and I would like to gracefully close the connection when I'm done performing my query. I can't find a way to do this. Is it possible? Thanks!

Most helpful comment

The ldap client has an undocumented method called destroy that will close the connection and not allow reconnection

https://github.com/mcavage/node-ldapjs/blob/master/lib/client/client.js#L974

All 9 comments

I'm in the same case, seems like I'm suffering a connection leak :(

Are you guys are using SSL and getting a "ECONNRESET" which crashes node? If so I was previously having the same issue and did 2 things

  1. I wrap the work in a function, I still use client.unbind() but since doing this I have not seen re-occurences.
  2. I catch the exception just in case so it doesn't crash node

process.on('uncaughtException', function (err) { if (err.code === "ECONNRESET") { console.log(err.stack); } else {process.exit;} })

I should also add I've had similar issues with TLS outside of ldapjs

No, in my case just found it was a problem with passport ldap strategy. Unbind is working OK and actually closing connections in the right way. Passport was leaking connections cause my implementation wasn't unbinding connections.

The ldap client has an undocumented method called destroy that will close the connection and not allow reconnection

https://github.com/mcavage/node-ldapjs/blob/master/lib/client/client.js#L974

Thank you ! Calling client.destroy() inside the search callback closes the connection.

Is doing client.destroy() a right thing to do?
Won't destroying the connection and again recreating it, affect the performance.
I'm using client.destroy() presently but not sure of the right way. Maybe reusing the same connection is ideal...

After i tried the option reconnect: true i could find that once the connection is reset its getting connected again. This may be a right thing to do but need further inputs from all...

@prajnavantha Are you getting the ECONNRESET error with the reconnect: true option?

No... I'm not getting an ECONNRESET after reconnect: true. It seems to be working fine. I'm still observing though.

Closing as the documentation is clarified in #393. Please open a new issue if you have further questions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atiertant picture atiertant  路  6Comments

sorccu picture sorccu  路  5Comments

UziTech picture UziTech  路  4Comments

sean256 picture sean256  路  5Comments

lmusat picture lmusat  路  5Comments