node-ldapjs icon indicating copy to clipboard operation
node-ldapjs copied to clipboard

LDAPJS keeps trying to connect to LDAP when no bind attempt occurs

Open jontowles opened this issue 8 years ago • 2 comments

I have taken multiple Packet Captures trying to figure out why ECONNRESET's occur.

I have found that even though you are not attempting to do any binds or LDAP actions that LDAPJS will try to connect to our LDAP server and eventually disconnect and just keep trying to re-connect.

This behavior doesn't seem to be by design. Can we get some clarification on this?

jontowles avatar May 24 '16 13:05 jontowles

I was fighting with this recently and after reviewing the client file in the library I realized the idle event wasn't being emitted if I didn't create a bind first. I haven't spent too much time reviewing this code to see what is going on, but if I have time one day maybe I can create a pull request. For now I will likely default back to using OpenLDAP library.

You can hook up to the idle event like so:

const client = ldap.createClient({
    url: `ldap://my-dc`,
    idleTimeout: 10 // Close due to inactivity
});

client.on('idle', event => {
    console.log("Timed out")
});

// Timed out is never printed

The result of this was I never received a idle event, so I decided to put a test bind in there and I started to received the idle event.

const ldap = require('ldapjs');
const client = ldap.createClient({
    url: `ldap://my-dc`,
    idleTimeout: 10 // Close due to inactivity
});

client.bind("[email protected]","Password", (err,res) => {
    if(err)
        console.log(err)
});

client.on('idle', event => {
    console.log("Timed out")
});

// Console now prints Timed out

tastypackets avatar Feb 14 '18 21:02 tastypackets

It sounds like the library assumes every connection will at least perform an anonymous bind before issuing any other messages. And this assumption leads to the idle code relying on the bind to be performed before it kicks in. I'd consider a PR that changes this or at least one that documents this behavior.

jsumners avatar Aug 27 '19 22:08 jsumners

👋

On February 22, 2023, we released version 3 of this library. As a result, we are closing this issue/pull request.

Please see issue #839 for more information, including how to proceed if you feel this closure is in error.

jsumners avatar Feb 22 '23 19:02 jsumners