Skip to content

Conversation

@thibaut-pascal
Copy link
Contributor

The mDNS daemon's shutdown mechanism was incomplete. When shutting down, the daemon would simply stop without properly cleaning up resources:

  • Registered services were not unregistered (no goodbye packets sent to the network, even if this is optional, this is nice to have)
  • Active browse operations were not stopped or notified
  • Hostname resolution queries were left hanging
  • Pending retransmissions remained in the queue

This could lead to:

  • Services remaining advertised on the network after shutdown
  • Client applications not being notified that operations were stopped
  • Potential resource leaks

Solution

Added a comprehensive cleanup mechanism that is called during shutdown:

  1. Service cleanup: All registered services now send goodbye packets (TTL=0) on all interfaces before shutdown
  2. Browse cleanup: All active browse operations are stopped and receive SearchStopped events
  3. Hostname resolution cleanup: All active hostname resolution operations are stopped and notified
  4. Retransmission cleanup: Pending retransmissions are cleared

Changes

  • Added cleanup() method to Zeroconf struct in service_daemon.rs
  • Modified the run loop to call cleanup() when Command::Exit is received
  • Proper notification sent to all active listeners before shutdown

- Send goodbye packets for all registered services
- Stop browse and hostname resolution operations
- Notify clients with SearchStopped events
Copy link
Owner

@keepsimple1 keepsimple1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for your PR! Looks really good, only a couple of minor comments inline.

debug!("Stopping browse during shutdown: {}", &ty_domain);
if let Some(sender) = self.service_queriers.remove(&ty_domain) {
// Notify the client
if let Err(e) = sender.send(ServiceEvent::SearchStopped(ty_domain.clone())) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I guess this clone is not required? (Ignore me if the borrow checker requires it)

if let Some((sender, _timeout)) = self.hostname_resolvers.remove(&hostname) {
// Notify the client
if let Err(e) =
sender.send(HostnameResolutionEvent::SearchStopped(hostname.clone()))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here: is clone required?

@keepsimple1 keepsimple1 added the enhancement New feature or request label Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants