fix: make rescan resilient to a transient empty set and per-interface… · python-zeroconf/python-zeroconf@423f875 · GitHub
Skip to content

Commit 423f875

Browse files
committed
fix: make rescan resilient to a transient empty set and per-interface bind failure
normalize_interface_choice raises RuntimeError for an All/Default instance that transiently resolves to zero addresses during adapter churn; catch it as a logged no-op so a momentary down state doesn't crash a caller's adapter-change handler. Make a per-interface endpoint-creation failure roll back and skip (log_warning_once) rather than abort the whole reconcile, so other interfaces still come up and get re-announced, matching the documented best-effort contract. Log a non-Windows IPV6_MULTICAST_IF read failure at warning (Windows WSAEINVAL stays debug) since a wrong-index leave leaks the membership.
1 parent c93f537 commit 423f875

3 files changed

Lines changed: 59 additions & 13 deletions

File tree

src/zeroconf/_engine.py

Lines changed: 16 additions & 4 deletions

src/zeroconf/_transport.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from __future__ import annotations
2424

2525
import asyncio
26+
import logging
2627
import socket
28+
import sys
2729
from typing import cast
2830

2931
from ._logger import log
@@ -111,7 +113,12 @@ def make_wrapped_transport(transport: asyncio.DatagramTransport) -> _WrappedTran
111113
try:
112114
multicast_index = sock.getsockopt(socket.IPPROTO_IPV6, socket.IPV6_MULTICAST_IF)
113115
except OSError as exc:
114-
log.debug("Unable to read IPV6_MULTICAST_IF, using default index 0: %s", exc)
116+
# Windows rejects this read (WSAEINVAL) for every v6 socket, so it is
117+
# expected and benign there; keep it at debug. Elsewhere a failure is
118+
# unexpected and means a later group leave uses the wrong index (a
119+
# benign no-op that leaks the membership), so surface it at warning.
120+
level = logging.DEBUG if sys.platform == "win32" else logging.WARNING
121+
log.log(level, "Unable to read IPV6_MULTICAST_IF, using default index 0: %s", exc)
115122
return _WrappedTransport(
116123
transport=transport,
117124
is_ipv6=is_ipv6,

tests/test_interface_update.py

Lines changed: 35 additions & 8 deletions

0 commit comments

Comments
 (0)