agnat/node_mdns

Handle getaddrinfo error gracefully

Closed this issue · 5 comments

cb(errnoException(err, 'getaddrinfo'));

In case there's a getaddrinfo error event, the library will fail. I wonder if we can handle it gracefully rather than crashing the whole process.

A possible solution would be to replace

cb(errnoException(err, 'getaddrinfo'));

with

cb(undefined, []);

What would be your take @agnat ?

NOTE: We already modified the resolver sequence to exclude IPV6

agnat commented

Hi @volumio,
you're right. A simple runtime error should not crash the process. However, this library is very old and hasn't had any issues like that in a long time. So, before I start chasing a ghost could you confirm real quick that you actually have an error handler ... like you should. 😉

Hi @agnat thanks for pointing us to the error handler doc, I somehow missed it! We are going to implement it and report back.
Adding @MERVINIO in the discussion

I'm also getting this crash (in a HomeBridge plugin, running on a raspberry PI). I'm only using the mDNS browser, not adding any services. And I've added a try/catch around my only call to the mdns library, but I'm still getting the SIGTERM.

Here is my relevant bit of code:

 discoverDevices() {
    const browser = mdns.createBrowser(mdns.tcp('iotsa'), 4321);
    browser.on('serviceUp', service => {
      this.mdnsServiceUp(service);
    });
    browser.on('serviceDown', service => {
      this.mdnsServiceDown(service);
    });
    try {
      browser.start();
    } catch(ex) {
      this.log.error('mdns.start exception: ', ex);
    }
  }

And here's the stack trace, which unfortunately doesn't tell me where the getaddrinfo call originated from:

Error: getaddrinfo -3008
    at errnoException (/home/jack/src/jack-git/homebridge-lissabon/node_modules/mdns/lib/resolver_sequence_tasks.js:199:11)
    at getaddrinfo_complete (/home/jack/src/jack-git/homebridge-lissabon/node_modules/mdns/lib/resolver_sequence_tasks.js:112:10)
    at GetAddrInfoReqWrap.oncomplete (/home/jack/src/jack-git/homebridge-lissabon/node_modules/mdns/lib/resolver_sequence_tasks.js:120:9)
agnat commented

And I've added a try/catch around my only call

How is that supposed to work, @jackjansen? You can't catch asynchronous errors. Please read a node tutorial or primer. This is not the right place to discuss this.

running on a raspberry PI

Lots of people are doing this. Just do your own research and you're going to be fine.

Hope this helps...

Further update on our end, in fact, by applying proper error handling as suggested in the documentation, we were able to handle gracefully the error thrown.

See: http://agnat.github.io/node_mdns/user_guide.html#error_handling