keepsimple1 / mdns-sd

Rust library for mDNS based Service Discovery
Apache License 2.0
89 stars 38 forks source link

Not consistent shutdowns and no way to know if shut down? #148

Closed CosminPerRam closed 7 months ago

CosminPerRam commented 7 months ago

I've created a reproducible (running on 0.9.3):

use mdns_sd::{ServiceDaemon, ServiceInfo};

fn main() {
    let mdns = ServiceDaemon::new().unwrap();
    mdns.shutdown().unwrap();

    let service_type = "_mdns-sd-my-test._udp.local.";
    let instance_name = "my_instance";
    let ip = "192.168.1.12";
    let host_name = "192.168.1.12.local.";
    let port = 5200;
    let properties = [("property_1", "test"), ("property_2", "1234")];

    let my_service = ServiceInfo::new(
        service_type,
        instance_name,
        host_name,
        ip,
        port,
        &properties[..],
    ).unwrap();

    mdns.register(my_service).unwrap();

    mdns.shutdown().unwrap();
}

This example consists of creating a daemon, shutting it down then registering a service and then shutting it down again, after running it multiple times, sometimes I get panics (due to unwrapping in the example) and sometimes not, the problem here is that this is not consistent.

Console output cosminperram@cosminsmbpro untitled % cargo r Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running `target/debug/untitled` thread 'main' panicked at src/main.rs:23:31: called `Result::unwrap()` on an `Err` value: Msg("flume::channel::send failed: sending on a closed channel") note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace cosminperram@cosminsmbpro untitled % cargo r Finished dev [unoptimized + debuginfo] target(s) in 0.01s Running `target/debug/untitled`

Another problem would be of how could I know if the daemon has a closed channel? Looking for something simple like is_running.

Hope I haven't missed anything related these issues in docs, if I did, please state so. Thanks for this library!

keepsimple1 commented 7 months ago

sorry I was out for a few days. I will look into this and get back to you.

keepsimple1 commented 7 months ago

Thanks for opening this issue. I've created a PR #149 to address this. Let me know if that helps your case.

CosminPerRam commented 7 months ago

Looks great, thanks for the quick implementation.

keepsimple1 commented 7 months ago

PR is merged into main. If you can check whether it's working for you, that'll be great! If any issues, please also let me know, thanks!

CosminPerRam commented 7 months ago

Hey, I didn't had the time to test it today, I'll definitely try it tomorrow.

CosminPerRam commented 7 months ago

Nevermind my last message, I got to try status and shutdown and they work as expected, thanks, awaiting the new release (:

keepsimple1 commented 7 months ago

The new release is published ;-)