Skip to content

fix: do not record an interface address whose multicast join failed - #523

Merged
keepsimple1 merged 1 commit into
mainfrom
fix/multicast-join-per-intf-family
Oct 17, 2026
Merged

keepsimple1 merged 1 commit into
mainfrom
fix/multicast-join-per-intf-family

Conversation

@keepsimple1

Copy link
Copy Markdown
Owner

Addresses the next items in #514:

  • Constructor join failures are logged as skipped but still insert the address.
  • An occupied add_interface entry inserts a new address and emits IpAdd after a failed join.

In both cases the address was treated as live even though the socket could not receive mDNS on it. And because it was recorded, the periodic IP check never retried the join.

Change

Zeroconf::new and add_interface now share one helper, add_intf_addr:

  • Multicast membership is per interface and per IP version. The helper joins only when the interface has no recorded address of that version yet. Another address of the same version (e.g. the link-local and global IPv6 addresses of one interface) reuses the membership instead of joining again, which would fail with AddrInUse (WSAEINVAL on Windows). This mirrors the leave side, which leaves only when the last address of a version is gone.
  • A genuine join failure records nothing and emits no IpAdd. The next IP check sees the address as new and retries the join.
  • The IPv4 AddrInUse handling from fix: record an interface whose multicast join failed, ending an endless retry #513, for different interfaces sharing one address, is unchanged.

Tests

  • test_second_address_reuses_interface_membership: a second IPv4 and IPv6 address on an interface that already holds both memberships is recorded without a join.
  • test_failed_join_does_not_record_address: a failed join on a new interface, or on a known interface without that version's membership, records nothing and emits no IpAdd.

🤖 Generated with Claude Code

Addresses items 2 and 3 of #514:

- `Zeroconf::new` logged a failed join as "Skipped" but still recorded the
  address, so the IP check never retried the join.
- `add_interface` recorded a new address on a known interface, and emitted
  `IpAdd`, even if its join failed.

Both now go through `add_intf_addr`, which joins only when the interface
holds no membership for that IP version yet. Membership is per interface
and per IP version, so another address of the same version reuses it
instead of joining again, which would fail with `AddrInUse` (`WSAEINVAL` on
Windows), e.g. the link-local and global IPv6 addresses of one interface.
A genuine join failure records nothing, and the next IP check retries it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1
keepsimple1 merged commit 9ca5b67 into main Oct 17, 2026
4 checks passed
@keepsimple1
keepsimple1 deleted the fix/multicast-join-per-intf-family branch October 17, 2026 04:04
keepsimple1 added a commit that referenced this pull request Nov 14, 2026
Problem:

The multicast sockets are set up only once, when the daemon starts, and failures were only logged at debug!. A daemon that couldn't bind sockets (neither IPv4 or IPv6) still started, register() returned Ok, and status() said Running. Such failures can't be reported as a DaemonEvent either, since no monitor exists that early. Failed multicast joins on an interface were likewise only logged.

Changes:

- new() fails when nothing can work. ServiceDaemon::new() / new_with_port() now create both sockets and register them with the poller before spawning the daemon thread. They return an error if neither the IPv4 nor the IPv6 socket can be bound, or if registering with the poller fails (previously the daemon thread just exited with a debug log). If only one socket fails (e.g. a host without IPv6), the daemon still runs.

- DaemonStatus::Running(RunningState). RunningState is a snapshot of the daemon's local setup, as of when it handled the status() request. It does not say whether packets get delivered or whether services can be found.

ipv4_socket() / ipv6_socket() return a SocketState, with:
is_bound(): whether that multicast socket was bound;
bind_error(): why it failed, if it did, so callers can tell "no IPv6 here" from "port in use".
enabled_intfs() returns the enabled interfaces the daemon uses, ordered by index, as EnabledIntf: name(), index(), and ipv4() / ipv6(), each an Option<Membership> (None if the daemon has no address of that version there). Membership has:
addrs(): the addresses of that version on the interface;
is_joined() / join_error(): whether the multicast join worked, or the error from the last failed attempt, which is retried at the next IP check.
All four public types are #[non_exhaustive] with private fields, so more state can be added later without breaking anyone.

Join failures are tracked. A failed join records nothing in my_intfs (since fix: do not record an interface address whose multicast join failed #523), so failures are kept in a separate map. An entry is cleared when a later join on that interface and IP version succeeds, when the address is disabled or invalid, or when the IP check no longer finds it. The status is now built on request, so the stored status field is gone.

Docs. new() / new_with_port() said an unusable port is reported through monitor(), which was never the case. They now describe the new behavior, and status() says its result is a snapshot.

Breaking change

DaemonStatus::Running is now DaemonStatus::Running(RunningState). Code matching or comparing it needs DaemonStatus::Running(_). That's a compile error rather than a silent behavior change, but it needs a minor version bump (0.22).

Part of #514. Also address issue #544.
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

Successfully merging this pull request may close these issues.

1 participant