Title: `async_update_interfaces()` does not recover an interface that was re-created with the same address · Issue #1947 · python-zeroconf/python-zeroconf · GitHub
Open Graph Title: `async_update_interfaces()` does not recover an interface that was re-created with the same address · Issue #1947 · python-zeroconf/python-zeroconf
X Title: `async_update_interfaces()` does not recover an interface that was re-created with the same address · Issue #1947 · python-zeroconf/python-zeroconf
Description: Summary When a network interface disappears and comes back with the same IP address (driver reset, PCI remove/rescan, USB NIC replug, ip link del + re-add), the kernel gives it a new ifindex. The existing responder socket and the listen ...
Open Graph Description: Summary When a network interface disappears and comes back with the same IP address (driver reset, PCI remove/rescan, USB NIC replug, ip link del + re-add), the kernel gives it a new ifindex. The e...
X Description: Summary When a network interface disappears and comes back with the same IP address (driver reset, PCI remove/rescan, USB NIC replug, ip link del + re-add), the kernel gives it a new ifindex. The e...
Opengraph URL: https://github.com/python-zeroconf/python-zeroconf/issues/1947
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`async_update_interfaces()` does not recover an interface that was re-created with the same address","articleBody":"### Summary\n\nWhen a network interface disappears and comes back with the same IP address (driver reset, PCI remove/rescan, USB NIC replug, `ip link del` + re-add), the kernel gives it a new ifindex. The existing responder socket and the listen socket's group membership still refer to the old ifindex, so mDNS on that interface stops working: nothing is received, and sends fail with `[Errno 101] Network unreachable`.\n\n`async_update_interfaces()` (added in #1797) doesn't recover from this. It diffs on `(address, scope_id)`, and for IPv4 (and global IPv6, scope 0) that key is the same before and after the interface is re-created, so the call is a no-op.\n\n### Reproduction\n\nzeroconf 0.154.0, Python 3.13, Linux 6.8. The script below uses a veth pair and a network namespace, so it has to run as root, e.g. `docker run --rm --privileged python:3.13-alpine` with `iproute2` installed.\n\n\u003cdetails>\u003csummary>repro.py\u003c/summary>\n\n```python\n\"\"\"Reproduce: async_update_interfaces() does not recover an interface that was\nre-created with the same address (new ifindex). Run as root (needs netns).\n\n server: Zeroconf bound to 10.9.0.1 on veth \"va\", registers a service\n client: a fresh Zeroconf in netns \"peer\" (10.9.0.2 on \"vb\") resolves it\n\"\"\"\nimport asyncio, os, socket, subprocess, sys\nfrom zeroconf import IPVersion, __version__\nfrom zeroconf.asyncio import AsyncServiceInfo, AsyncZeroconf\n\nTYPE, NAME = \"_test._tcp.local.\", \"Repro._test._tcp.local.\"\n\ndef sh(cmd):\n subprocess.run(cmd, shell=True, check=True)\n\ndef make_veth():\n sh(\"ip link add va type veth peer name vb && ip link set vb netns peer\"\n \" && ip addr add 10.9.0.1/24 dev va && ip link set va up\"\n \" && ip netns exec peer sh -c 'ip addr add 10.9.0.2/24 dev vb && ip link set vb up && ip link set lo up'\")\n\ndef ifindex():\n return socket.if_nametoindex(\"va\")\n\nasync def resolve():\n # Fresh client process each time so nothing is answered from a cache.\n code = (\"import asyncio\\nfrom zeroconf import IPVersion\\nfrom zeroconf.asyncio import AsyncZeroconf, AsyncServiceInfo\\n\"\n \"async def m():\\n\"\n \" zc = AsyncZeroconf(interfaces=['10.9.0.2'], ip_version=IPVersion.V4Only)\\n\"\n f\" i = AsyncServiceInfo('{TYPE}', '{NAME}')\\n\"\n \" print('found' if await i.async_request(zc.zeroconf, 3000) else 'NOT FOUND')\\n\"\n \" await zc.async_close()\\n\"\n \"asyncio.run(m())\\n\")\n p = await asyncio.create_subprocess_exec(\"ip\", \"netns\", \"exec\", \"peer\", sys.executable, \"-c\", code,\n stdout=asyncio.subprocess.PIPE)\n out, _ = await p.communicate()\n return out.decode().strip()\n\nasync def main():\n print(\"zeroconf\", __version__)\n sh(\"ip netns add peer\")\n make_veth()\n aiozc = AsyncZeroconf(interfaces=[\"10.9.0.1\"], ip_version=IPVersion.V4Only)\n info = AsyncServiceInfo(TYPE, NAME, addresses=[socket.inet_aton(\"10.9.0.1\")], port=1234,\n server=\"repro.local.\")\n await aiozc.async_register_service(info)\n print(f\"1. initial (va ifindex {ifindex()}):\", await resolve())\n\n sh(\"ip link del va\") # what a driver reset / PCI rescan / USB replug does\n make_veth()\n print(f\"2. va re-created, same address (ifindex {ifindex()}):\", await resolve())\n\n await aiozc.zeroconf.async_update_interfaces()\n print(\"3. after async_update_interfaces():\", await resolve())\n\n await aiozc.zeroconf.async_update_interfaces(interfaces=[])\n await aiozc.zeroconf.async_update_interfaces(interfaces=[\"10.9.0.1\"])\n print(\"4. after update_interfaces([]) then (['10.9.0.1']):\", await resolve())\n await aiozc.async_close()\n\nasyncio.run(main())\n```\n\u003c/details>\n\nOutput:\n\n```\nzeroconf 0.154.0\n1. initial (va ifindex 3): found\n2. va re-created, same address (ifindex 5): NOT FOUND\n3. after async_update_interfaces(): NOT FOUND\n4. after update_interfaces([]) then (['10.9.0.1']): found\n```\n\nMeanwhile the server logs `Error with socket ... (('10.9.0.1', 5353))): [Errno 101] Network unreachable` for its sends.\n\n### Why\n\nFor IPv4, `IP_ADD_MEMBERSHIP` and `IP_MULTICAST_IF` given an address are resolved to a device when the socket option is set. Once that device is unregistered, the membership is gone and the socket's multicast interface points at a dead ifindex. A new device with the same address doesn't revive either one. Global IPv6 addresses (scope 0) should be affected the same way. Link-local IPv6 already works, because its scope_id is the ifindex and changes with it.\n\n### Real-world impact\n\nHome Assistant runs on a host whose Intel I226 (`igc`) NIC occasionally drops its link. A watchdog recovers it with a PCI remove/rescan, so `eno1` comes back with the same address and a new index. After that, everything HA advertises over mDNS (the HomeKit bridge, `_home-assistant._tcp`) disappears from the LAN until HA restarts.\n\n### Workaround\n\nForce a full re-bind: call `async_update_interfaces(interfaces=[])`, then call it again with the real list. The caller also has to detect the re-creation itself, e.g. by polling `socket.if_nameindex()`.\n\n### Possible fix\n\nInclude the interface index in the reconcile key for IPv4 and global IPv6 too, e.g. `(address, scope_id, ifindex)`:\n- **Desired side:** resolve each address to its adapter index (`ifaddr` already exposes `adapter.index`) in `normalize_interface_choice`.\n- **Current side:** record the index when the responder socket is created, next to `multicast_index`.\n\nA changed index would then make the sender look like remove + add, and the existing code paths already handle that, including the re-announce. I'm happy to send a PR if that direction sounds right.\n","author":{"url":"https://github.com/jpc","@type":"Person","name":"jpc"},"datePublished":"2026-11-19T12:51:08Z","url":"https://github.com/python-zeroconf/python-zeroconf/issues/1947"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ea5a8bba-5571-4e5d-574a-f59c42a27cd1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BC28:25CAB3:45F4:5C5B:6B007D38 |
| html-safe-nonce | 3f9175f9ca3fda6a4c75c5729510de256bcb84f66e4dfffb6811bb2531136709 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQzI4OjI1Q0FCMzo0NUY0OjVDNUI6NkIwMDdEMzgiLCJ2aXNpdG9yX2lkIjoiNjA1MjE4ODc3MjUwODkyNTI0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ed542ad3e469a811f8c52c9958de303384f2078f976ee1336a769726beb41e60 |
| hovercard-subject-tag | issue:6489980688 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-zeroconf/python-zeroconf/1947/issue_layout |
| twitter:image | https://opengraph.githubassets.com/57f339b703f96ce7c1cda923a802dd4f28d2ac013012163281ff927c9a465eff/python-zeroconf/python-zeroconf/issues/1947 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/57f339b703f96ce7c1cda923a802dd4f28d2ac013012163281ff927c9a465eff/python-zeroconf/python-zeroconf/issues/1947 |
| og:image:alt | Summary When a network interface disappears and comes back with the same IP address (driver reset, PCI remove/rescan, USB NIC replug, ip link del + re-add), the kernel gives it a new ifindex. The e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jpc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 82c186f13e104004ab7bdb779f3195e59dd38bfde531aaa74b76470fc2462b83 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-zeroconf/python-zeroconf git https://github.com/python-zeroconf/python-zeroconf.git |
| octolytics-dimension-user_id | 120192235 |
| octolytics-dimension-user_login | python-zeroconf |
| octolytics-dimension-repository_id | 21548731 |
| octolytics-dimension-repository_nwo | python-zeroconf/python-zeroconf |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 21548731 |
| octolytics-dimension-repository_network_root_nwo | python-zeroconf/python-zeroconf |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d1bc2aa1939001689f5ce935982c10a6138f745c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width