0

I have an LdapJS server which implements standard operation and an extended operation to check health:

const server = ldap.createServer();
server.exop('healthcheck', (req, res, next) => {
    res.end();
    console.log('ended');
    return next();
});
...

Then I wrote a simple client script to ping healthcheck service:

const { createClient } = require('ldapjs');

const client = createClient({
    url: 'ldap://localhost:1389',
    timeout: 2000,
    connectTimeout: 2000
});

client.exop('healthcheck', (err, value, res) => {
    if (err) {
        console.log(`ERROR: ${err.message}`); 
        process.exit(1);
    }
    else {
        console.log(`STATUS: ${res.status}`);
        process.exit(0);
    }
});

The problem is that the exop is correctly received by server (I can see the log inside its callback), but the client always logs: ERROR: request timeout (client interrupt).

Why the request is not correctly terminated?

EDIT

I wrote a mocha test for the exop and it works. Seems that the problem is related to the standalone call in healthcheck script.

describe('#healthcheck()', function () {
    before(function () {
        server = createServer();
        server.listen(config.get('port'), config.get('host'), () => {});
    });

    after(function () {
        server.close();
    });

    it('should return status 0', function (done) {
        const { createClient } = require('ldapjs');
        const client = createClient({
            url: 'ldap://localhost:1389',
            timeout: 2000,
            connectTimeout: 2000
        });

        client.exop('healthcheck', (err, value, res) => {
            should.not.exist(err);
            res.status.should.be.equal(0);
            client.destroy();
            return done();
        });
    });
});
Marco Stramezzi
  • 2,143
  • 4
  • 17
  • 37
  • Did you try another port ? Also timeout being in millisecond, perhaps 2000 is not enough. I would try to set Infinity (or leave empty to fallback on default config) to see what happens before setting a reasonable value. – EricLavault Dec 19 '18 at 20:27
  • I tried both your suggestions but they did not work. If I set timeout to Infinity, the request keeps pending forever. – Marco Stramezzi Dec 20 '18 at 09:31

0 Answers0