简体   繁体   English

NodeJS上的ZMQ:捕获错误

[英]ZMQ on NodeJS: catching errors

I've been working with the ZMQ binding for NodeJS for a while now but I never received such error: 我已经使用NodeJS的ZMQ绑定已有一段时间了,但是我从未收到这样的错误:

Error: Interrupted system call
    at Socket._ioevents (/path/node_modules/zmq/lib/index.js:144:22)
    at Socket._flush (/path/node_modules/zmq/lib/index.js:273:23)

Now, I have a big system that creates topologies. 现在,我有一个创建拓扑的大型系统。 For me it's really difficult given such error to go and see which node of the topology screwes up. 对我来说,鉴于这样的错误,要查看拓扑的哪个节点确实很困难。 The idea is to put some kind of try / catch to catch this error and log where it happens. 想法是进行某种尝试/捕获以捕获此错误并记录错误发生的位置。

Is there a way to do this? 有没有办法做到这一点? I don't think the following code will work: 我认为以下代码无效:

try {
    receiver.on('message', function(data){
        //do stuff  
    });
}
catch(e) {
    console.log("error " + e)
}

Since I have to modify a huge part of the software with all these try/catch, I want to be sure if this is the right way (which I'm almost sure is not) to catch that kind of error. 由于我必须使用所有这些try / catch来修改软件的很大一部分,因此我想确定这是否是捕获此类错误的正确方法(我几乎确定不是)。

Anybody can confirm this? 有人可以确认吗? Otherwise anybody with experience can enlighten me on the error I'm receiving? 否则,任何有经验的人都可以启发我我收到的错误吗?

Thanks 谢谢

EDIT: after a quick test I can confirm 99% this approach is not working. 编辑:快速测试后,我可以确认99%的这种方法不起作用。 Is there a way in which I can get where that error comes from? 有没有一种方法可以弄清错误的出处?

2nd EDIT: I discovered that this problem may be related to the upgrade from version 2.0 to version 2.1 of ZMQ. 第2次编辑:我发现此问题可能与ZMQ的2.0版升级到2.1版有关。 This is the link to the changelog http://www.zeromq.org/docs:2-1-upgrade while the following is the part that concerns me most: 这是更改日志的链接http://www.zeromq.org/docs:2-1-upgrade,而以下是我最关心的部分:

In 2.0, ZeroMQ would ignore any interrupted system calls, which meant that no ZeroMQ
call would ever return EINTR if a signal was received during its operation. This caused
problems with loss of signals such as SIGINT (Ctrl-C handling), especially for language
runtimes. In 2.1, any blocking ZeroMQ call such as zmq_recv[3] will return EINTR if it
is interrupted by a signal.

So does anybody knows how to wrap my blocking calls to handle EINTR ? 那么有人知道如何包装我的阻塞调用来处理EINTR吗?

I think that your try-catch block is wrapping only the registration of the callback itself. 我认为您的try-catch块仅包装了回调本身的注册。 So when an exception is actually raised, there is no try-catch to handle it. 因此,当实际引发异常时,没有尝试捕获来处理它。 It should look like 它看起来像

receiver.on('message', function(data){
    try {
        //do stuff
    }
    catch(e) {
        console.log("error " + e);
    }  
});

In fact any code that uses ZMQ calls should be wrapped with try-catch since it can raise exceptions. 实际上,任何使用ZMQ调用的代码都应使用try-catch进行包装,因为它可能引发异常。 You can check yourself at GitHub. 您可以在GitHub上进行检查。 I think that your particular exception may be raised around here , but not 100% sure ;-) 我认为您的特殊情况可能会在此处引起 ,但不是100%确定;-)

Hope it helped, cheers ;-) 希望它有帮助,欢呼;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM