Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect, this.bind issue #106

Open
guillaumefe opened this issue Dec 30, 2017 · 2 comments
Open

Can't connect, this.bind issue #106

guillaumefe opened this issue Dec 30, 2017 · 2 comments

Comments

@guillaumefe
Copy link

guillaumefe commented Dec 30, 2017

I surely miss something.

I use slapd on debian 8.

When I put this.bind into connect, it never finishes (even if I put connecttimeout to 1 or 10 or whatever).

On the other hands ldap.bind works well in the new LDAP callback.

const LDAP = require('ldap-client');

var connect = function(ctx) {
    ctx.bind({
        binddn: 'cn=admin,dc=my,dc=io',
        password: 'pass'
    }, function(err) {
        if(err) console.log(err);
    }); 
}

var ldap = new LDAP({
    uri:             'ldap://localhost',
        validatecert:    false,
        connecttimeout:  -1,
        base:            'dc=my,dc=io',
        attrs:           '*',
        filter:          '(objectClass=*)',
        scope:           2,
        connect:         function(err) {
            if(err) console.log(err);
            connect(this);
        },
        disconnect:      function() {},        
}, function(err) {
    if(err) console.log(err);
    connect(ldap);
});

I'm stuck, please could you help me to understand or explain best what is happening?

@guillaumefe
Copy link
Author

Up please

@mwri
Copy link

mwri commented Mar 28, 2019

I just hit this too; you write a connect function as per the example in the README.md and it locks the whole VM up, so it's not yielding at all. Nasty.

I was able to work around this as follows, instead of this (which locks nodejs up):

new LDAP({
    connect: function () {
        this.simplebind({
            binddn: binddn,
            password: password,
        }, function (err) {
            console.log("this is never called");
        });
        console.log("this is never called; this.simplebind never returns");
    },
});

I instead used process.nextTick like this, which then works as expected. Obviously connect will complete without the bind necessarily finishing but in my case this is not an issue as I wrapped the whole thing in a promise, which can be resolved on successful bind, thus hiding the whole problem from the caller:

new LDAP({
    connect: function () {
        process.nextTick(() => {
            this.simplebind({
                binddn: binddn,
                password: password,
            }, function (err) {
                console.log("this IS now called, with an error if something went wrong");
            });
            console.log("this IS now called; this.simplebind returns");
        });
    },
});

I guess there is a deadlock, or a race condition that stops bind working in the connect call synchronously, but I've not looked into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants