首页 > 解决方案 > LdapJS exop 请求超时

问题描述

我有一个 LdapJS 服务器,它实现标准操作和扩展操作来检查运行状况:

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

然后我写了一个简单的客户端脚本来 ping 健康检查服务:

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

问题是exop服务器正确接收了 (我可以在其回调中看到日志),但客户端总是记录:ERROR: request timeout (client interrupt)

为什么请求没有正确终止?

编辑

我为 exop 写了一个 mocha 测试,它可以工作。似乎问题与运行状况检查脚本中的独立调用有关。

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

标签: node.jsldapldapjs

解决方案


推荐阅读