node.js - 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();
});
});
});
解决方案
推荐阅读
- oracle - Pro*C 动态查询具有 `in` 条件的`select`
- entity-framework-core - MassTransit:排队消费相关数据的不同消息
- python - Python - 是否有使用 Numpy 进行矩阵乘法的快速方法
- r - “sourceCpp 中的错误(“xx.cpp”)错误:构建共享库时发生错误 1。”
- git - 在一个“文件夹”下推几个分支
- mysql - SQL 未连接
- string - Powershell 根据电子邮件地址列表检查电子邮件地址
- python - 当行已满且 Tkinter 中的滚动条时如何使文本小部件跳到下一行
- android - 使用 Buildozer 构建的 Kivy 应用程序:您的应用程序当前针对 API 级别 27,并且必须至少针对 API 级别 29
- scheme - MIT Scheme 的 REPL 中是否有快速退出调试器的方法?