Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle mDNS (avahi-daemon) stop #56

Closed
thunderace opened this issue Dec 17, 2012 · 7 comments
Closed

How to handle mDNS (avahi-daemon) stop #56

thunderace opened this issue Dec 17, 2012 · 7 comments

Comments

@thunderace
Copy link

Hello, how is it possible to handle a stop/start of hte mDNS daemon (avahi-daemon for me on debian).

In case of daemon stop, what can we do to restart the advertising service?
Thx.

@agnat
Copy link
Owner

agnat commented Dec 17, 2012

Heh, good question. Not sure if it possible at all. I'll look into it.

On Dec 17, 2012, at 15:33, thunder notifications@github.com wrote:

Hello, how is it possible to handle a stop/start of hte mDNS daemon (avahi-daemon for me on debian).

In case of daemon stop, the client crash and need to be restarted.

Thx.


Reply to this email directly or view it on GitHub.

@thunderace
Copy link
Author

It's possible in python for example. Calibre, the e-book library management, handle such thing right. But i don't know how :)

@agnat
Copy link
Owner

agnat commented Dec 17, 2012

Well, obviously it's possible. What I meant is: It might not be fixable in mdns. If that's the case I'll report it upstream to the node/libuv guys...

On Dec 17, 2012, at 17:37, thunder notifications@github.com wrote:

It's possible in python for example. Calibre, the e-book library management, handle such thing right. But i don't know how :)


Reply to this email directly or view it on GitHub.

@agnat
Copy link
Owner

agnat commented Dec 17, 2012

Well, for me it doesn't crash. If the daemon is down while creating a browser I get an exception. When the daemon goes down while browsing I get an error event. Both is easy to handle:

var mdns = require('./lib/mdns');

try {
  var b = mdns.createBrowser(mdns.tcp('http'));
} catch (ex) {
  console.log('something bad happened. we better start over.')
}

b.on('error', function(error) {
  console.log('something bad happened. we better start over.')
});
b.start();

The error is a bit vague though. But I can't change that. mdns only forwards what the underlying library reports. However, in case of an unknown error it is probably best to set up a new browser and start over anyway. The only improvement on the mdns side I can think of is to attach the actual error code to the exception/error object. The source code looks a bit like I've tried that already and it probably wasn't that simple. However, I'll give it another try (See #57)...

Tested on ubuntu 11.10, node 0.8.12, mdns 1.0.0.

@thunderace
Copy link
Author

Sorry you arre right : no crash (i missed to attach the 'error' handler). The solution is to restart the browser/createAdvertisement. I will try this. back soon.

Thx

@thunderace
Copy link
Author

below code to handle avahi errors :

function createAdvertisement()  {
    try {
        var mdns_txt_record = {
            name: domoConfig.domoConf.svcName,
            port: domoConfig.domoConf.svcPort
    };
    var advert = mdns.createAdvertisement(mdns.tcp(domoConfig.domoConf.svcName) , domoConfig.domoConf.svcPort, {txtRecord: mdns_txt_record});
    advert.on('error', function(error) {
        console.log("advert ERROR ", error);
        setTimeout(createAdvertisement, 30 * 1000);
    });
    advert.start();
    } catch (ex){
        console.log("advert creation ERROR ");
        setTimeout(createAdvertisement, 30 * 1000);
    } 
} 
}

Thx for your help

@agnat
Copy link
Owner

agnat commented Dec 18, 2012

You're welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants