René's URL Explorer Experiment


Title: feat: add async_update_interfaces to rescan network interfaces at runtime by bdraco · Pull Request #1797 · python-zeroconf/python-zeroconf · GitHub

Open Graph Title: feat: add async_update_interfaces to rescan network interfaces at runtime by bdraco · Pull Request #1797 · python-zeroconf/python-zeroconf

X Title: feat: add async_update_interfaces to rescan network interfaces at runtime by bdraco · Pull Request #1797 · python-zeroconf/python-zeroconf

Description: Closes #1777. Summary Adds a runtime API to reconcile the sockets zeroconf uses to the live interface set, so an interface that appears or disappears no longer requires recreating the whole Zeroconf. async_update_interfaces (with a sync update_interfaces wrapper) adds a responder socket for each interface that showed up, tears down the socket for each interface that went away, and re-announces existing registrations when a new sender appeared. It accepts the same interfaces, ip_version, and apple_p2p arguments as the constructor, each defaulting to the construction-time value, so a caller reconfigures with the same vocabulary it started with. The listen socket is rebuilt when the new set needs a different address family; unicast mode is fixed at construction. How this maps to #1777 Works live, never tears down listeners for interfaces that haven't changed — an interface present in both the old and new set keeps its exact transport object; no teardown, no rebind, no packet loss on it. Accepts all the arguments we accept at startup — interfaces, ip_version, apple_p2p. Only tears down listeners for addresses that changed — the diff keys on (address, scope_id); only senders whose key left the desired set are closed, only keys that are new get a socket. An IP change is remove-old + add-new. Behavior No-op when nothing changed: if the reconciled set matches what is already bound, no socket is touched and nothing is re-announced. Re-announcement only fires when a new sender was actually added (a returning/new interface needs to advertise; removals need no re-announce on the survivors). Listen socket adapts when it must: a rescan that keeps the same address family never touches the listen socket; a set that needs a new family rebuilds it (re-joining the interfaces that stay), and moving a Default single-family instance to an explicit list converts its dual-use listen/responder socket to a pure listener, then adds per-interface responders for the whole set. The conversion rebuilds the socket clean so the new joins do not collide with the memberships it already held, and demotes it first so nothing double-announces. Details Zeroconf.__init__ retains interfaces, ip_version, and apple_p2p; the rescan re-runs normalize_interface_choice against the live set and brings each interface up through the same net.add_interface primitive construction uses, so setup and rescan stay in lockstep. (address, scope_id) keying lives on _WrappedTransport.interface_key (paired with _interface_key for the desired side), so link-local IPv6 addresses that repeat across interfaces don't collide; _WrappedTransport.multicast_interface gives the value membership calls take. New drop_multicast_member in net.py is the inverse of add_multicast_member (IP_DROP_MEMBERSHIP / IPV6_LEAVE_GROUP), swallowing the same benign errnos (including WSAEINVAL on Windows). Removal is proactive: the gone sender's protocol and reader/sender wrappers are dropped from the engine lists, then the transport is closed. Re-announce piggybacks on the existing _async_broadcast_service; the listener answers on whichever transport received the query, so a new reader needs no extra wiring. RFC 6762 section 8.3. AsyncZeroconf.async_update_interfaces delegates to Zeroconf, mirroring async_register_service. How a consumer drives this (e.g. Home Assistant) A consumer that constructs Zeroconf(interfaces=[...]) with an explicit address list calls async_update_interfaces(new_list) from its own adapter-change signal; the diff reconciles the new list against the bound sockets and leaves unchanged ones in place. Consumers with native adapter-change events use this directly; those without can opt into the polling monitor in the follow-up PR. This is the socket-side half of cases like home-assistant/core#59553 (it re-announces whatever ServiceInfo the consumer registered; correcting announced URL/TXT content after a network change is the consumer's job via async_update_service). Test plan tests/test_interface_update.py covers no-op (no sockets touched, no re-announce), default-to-stored-choice, ip_version/apple_p2p overrides, keep-unchanged-sender-untouched (same transport object), remove and re-add, re-announce on add, failed join, None responder rollback, the dual-use guard, the unicast no-listen-socket path, and the sync wrapper, plus _WrappedTransport.interface_key / multicast_interface / _interface_key unit tests. test_update_interfaces_reconciles_mixed_set drives the engine diff over a 4-sender v4+v6 set in one pass: keeps unchanged, drops gone, adds new, and distinguishes two interfaces sharing fe80::1 by scope_id (scope-2 kept, scope-3 dropped) end to end, asserting each gone interface leaves its group with its own representation. tests/utils/test_net.py::test_drop_multicast_member covers success, IPv6, benign errnos, reraise, no-IPv6, and the Windows WSAEINVAL path. _engine and _transport diff fully covered (lines and branches); compiled (REQUIRE_CYTHON=1) and pure-Python suites green; pre-commit run clean.

Open Graph Description: Closes #1777. Summary Adds a runtime API to reconcile the sockets zeroconf uses to the live interface set, so an interface that appears or disappears no longer requires recreating the whole Zerocon...

X Description: Closes #1777. Summary Adds a runtime API to reconcile the sockets zeroconf uses to the live interface set, so an interface that appears or disappears no longer requires recreating the whole Zerocon...

Opengraph URL: https://github.com/python-zeroconf/python-zeroconf/pull/1797

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8eda11a2-679b-99ce-40e4-c47116993851
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDC1C:D9D90:19210C:222E72:6B00831A
html-safe-nonce9c09b025d756fe2c078234f68699e1fd3d6534450ad26da07b5db9c97c61a906
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzFDOkQ5RDkwOjE5MjEwQzoyMjJFNzI6NkIwMDgzMUEiLCJ2aXNpdG9yX2lkIjoiNDI3NDMyMjk0NDc4MTQ4NDgyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac453829e9d6eabe6ebe137f83cc229688eef795cab64ef57e7231e1a3ce532d07
hovercard-subject-tagpull_request:3908190372
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python-zeroconf/python-zeroconf/pull/1797/files
twitter:imagehttps://avatars.githubusercontent.com/u/663432?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/663432?s=400&v=4
og:image:altCloses #1777. Summary Adds a runtime API to reconcile the sockets zeroconf uses to the live interface set, so an interface that appears or disappears no longer requires recreating the whole Zerocon...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4d3d8e50f02c1d7bf86d5acfa1d3bfe9366abd6528a6b429eb07a168429d2b61
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python-zeroconf/python-zeroconf git https://github.com/python-zeroconf/python-zeroconf.git
octolytics-dimension-user_id120192235
octolytics-dimension-user_loginpython-zeroconf
octolytics-dimension-repository_id21548731
octolytics-dimension-repository_nwopython-zeroconf/python-zeroconf
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id21548731
octolytics-dimension-repository_network_root_nwopython-zeroconf/python-zeroconf
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasedb758f8e02b8257935fb03edf81a3e76eb3abd11
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fpull%2F1797%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fpull%2F1797%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python-zeroconf%2Fpython-zeroconf
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
python-zeroconfhttps://github.com/python-zeroconf
python-zeroconfhttps://github.com/python-zeroconf/python-zeroconf
Codehttps://github.com/python-zeroconf/python-zeroconf
Issues50 (50)https://github.com/python-zeroconf/python-zeroconf/issues
Pull requests16 (16)https://github.com/python-zeroconf/python-zeroconf/pulls
Discussionshttps://github.com/python-zeroconf/python-zeroconf/discussions
Actionshttps://github.com/python-zeroconf/python-zeroconf/actions
Projectshttps://github.com/python-zeroconf/python-zeroconf/projects
Wikihttps://github.com/python-zeroconf/python-zeroconf/wiki
Security and quality5 (5)https://github.com/python-zeroconf/python-zeroconf/security
Insightshttps://github.com/python-zeroconf/python-zeroconf/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2Fnew%2Fchoose
bdracohttps://github.com/bdraco
masterhttps://github.com/python-zeroconf/python-zeroconf/tree/master
feat/async-update-interfaceshttps://github.com/python-zeroconf/python-zeroconf/tree/feat/async-update-interfaces
Conversation 75 https://github.com/python-zeroconf/python-zeroconf/pull/1797
Commits 23 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits
Checks 36 https://github.com/python-zeroconf/python-zeroconf/pull/1797/checks
Files changed https://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
feat: add async_update_interfaces to rescan network interfaces at runtime https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#top
Show all changes 23 commits https://github.com/python-zeroconf/python-zeroconf/pull/1797/files
48c5fe5 feat: add async_update_interfaces to rescan network interfaces at run… bdraco Jun 21, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/48c5fe5da6145306e3d40159b940de42546bd638
6199f8a Merge branch 'master' into feat/async-update-interfaces bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/6199f8ae2526212dfff05bbc494968908d9f7ab6
e3afb88 address review: guard Default kind-switch, unlock re-announce, copy i… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/e3afb881af7ee1c35cf845228b085f960da38d30
60eddff harden: narrow getsockopt mask logging, roll back per-interface add o… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/60eddffaae137801db91c2a5ae3c65cce58531ae
6e5d314 test: drive Default/unicast cases at the engine level to avoid real-m… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/6e5d3146cd01970ff177ee44077c444985440439
e05addd harden: cancel removed interface listener TC timers; warn on unexpect… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/e05adddebfaa556f25da0ed4326565d035afe7b9
3dae38b feat: rebuild listen socket on incompatible family change instead of … bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/3dae38b7d4bc10d62a5b13b8e05371d6a8e54903
d05d3e2 fix: rebuild listen socket safely - derive family from desired set, c… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/d05d3e2278ca2be105f9da7952b6aa0d3d178741
86771c6 refactor: drop redundant rebuild return value; trim duplicate rebuild… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/86771c6ca57a2a5bc04eeebb289c1d73803efd19
2058592 refactor: share interface-setup helpers between construction and rescan bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/2058592ab5c45a19b594a079ed0354b898e99b5a
2d4b61b feat: reconcile a Default single-family instance to an explicit set bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/2d4b61b4bdcae3cdc2114bc18585e8fe691e337a
2b37423 docs: correct the no-await invariant comment in _async_create_endpoints bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/2b37423eff40fd39f0c7e8d1dcdf1d6dd50e4dfa
59d9c80 refactor: dedup transport-list filtering; pop the demoted key instead… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/59d9c80babef4e7fc376c4bf76102677627a8fdd
12bba00 fix: warn when a staying interface fails to re-join on the rebuilt li… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/12bba0094961d5e61a9ed8a94caa03b44d3939a0
4657975 test: pin re-announce fan-out, ip-change, and v6 leave-index behavior bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/46579752de3bed33c1b7841538a306cdd7b0e1c8
4a2f0e3 fix: only swallow IPV6_V6ONLY read failure on Windows bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/4a2f0e35a613b2f1f69258e2fc34c3667782a807
4086ae2 fix: name the service in re-announce failures; widen sync update timeout bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/4086ae246fc85023191181ac9710898114446f96
37f6b1a fix: degrade getsockopt read failures instead of aborting bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/37f6b1af3448440446869f36734dd76412b7eb7c
c93f537 fix: surface an unreadable IPV6_V6ONLY at warning, document best-effo… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/c93f53763f70cd1325565cb0d6a75eb7d613c384
423f875 fix: make rescan resilient to a transient empty set and per-interface… bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/423f8752e97209807903b3a070afb806f703495b
55ca5ea fix: only swallow OSError when a per-interface endpoint fails bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/55ca5eadb9eaca810d7cf2f61178da2ee509a541
f0090e4 fix: don't degrade or crash on a listen-socket rebuild failure bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/f0090e4665c5c685aaa5e304058bb1042f72266f
c2df902 fix: don't drop a cancelled re-announce; document the apple_p2p raise bdraco Jun 22, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1797/commits/c2df9023b4ad3aa5eed7022e9e9d3c78e6e45626
Clear filters https://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
_core.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
_engine.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-8dc080e5555d9366069bd1bdbe1cee5bafd50ff8efc9e6ce469d6716bbf7663e
_listener.pxd https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
_listener.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
_transport.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-c394cbc8422ae77567361c7f435fc6de916373531558d0069bc3535fa7f7de1f
net.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-16e7dbbe84235183a0e3f58fa9fe2fce44a09848c2cb81a2c59775b27218135c
asyncio.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-96bdd1e4e7a9ff49c66e746ace69a44b9a538be08cc39b7c38139bb78e81cf14
test_interface_update.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-6c178c122681da1325df3cb27aaf36fe56f56d55b73d4103eec8f42d4c25af3c
test_net.py https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-b0722f491ed69822054e986e9b2dac8941d0a485c891d03d41651a8fd7a672a4
src/zeroconf/_core.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
View file https://github.com/python-zeroconf/python-zeroconf/blob/c2df9023b4ad3aa5eed7022e9e9d3c78e6e45626/src/zeroconf/_core.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1797/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
https://github.com/python-zeroconf/python-zeroconf/pull/1797/files#diff-334d60456692812966fc9644e6d71b6e2c60dfc6fb2d02d02d5fef6a480c360d
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1797/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.