简体   繁体   中英

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:

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.

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. 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. 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:

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 ?

I think that your try-catch block is wrapping only the registration of the callback itself. 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. You can check yourself at GitHub. I think that your particular exception may be raised around here , but not 100% sure ;-)

Hope it helped, cheers ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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