← 输入框|github.com|刷新
Skip to content

fix: skip adapter scan for interface lists with no IPv6 entries - #1919

Merged
bdraco merged 2 commits into
masterfrom
skip-adapter-scan-ipv4-list
Sep 28, 2026
Merged

bdraco merged 2 commits into
masterfrom
skip-adapter-scan-ipv4-list

Conversation

@bdraco

@bdraco bdraco commented Sep 28, 2026

Copy link
Copy Markdown
Member

Summary

An explicit interfaces list always scanned the adapters with ifaddr.get_adapters(), even when it only held IPv4 addresses and the result was never used. The scan is blocking and runs on the event loop, so it is now only done once the list has an interface index or an IPv6 address.

Fixes #1917

Test plan

New tests in tests/utils/test_net.py check that an IPv4 only list does not scan the adapters, and that a mixed list scans them once.

@bdraco
bdraco marked this pull request as ready for review September 28, 2026 09:31
@github-actions

Copy link
Copy Markdown

Thanks for contributing! A quick note: this project is in the process of moving from LGPL-2.1 to Apache 2.0, and may keep LGPL-2.1-or-later as an OR option so GPL-2.0-only projects can keep using the library, see #1835.

By continuing with this pull request you agree that this new contribution is offered under both Apache 2.0 and LGPL-2.1-or-later, so it is covered under either outcome.

This notice does not affect your previous contributions. If you would like to consent to relicensing those as well, please post the consent statement on #1835; silence is never treated as consent for past work.

If offering this contribution under these licenses does not work for you, no hard feelings; reply with the exact phrase I do not agree to the Apache 2.0 license or simply close this pull request.

@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.87%. Comparing base (bb91be5) to head (ebd5138).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1919   +/-   ##
=======================================
  Coverage   99.87%   99.87%           
=======================================
  Files          33       33           
  Lines        3911     3913    +2     
  Branches      568      568           
=======================================
+ Hits         3906     3908    +2     
  Misses          3        3           
  Partials        2        2           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 24 untouched benchmarks


Comparing skip-adapter-scan-ipv4-list (ebd5138) with master (bb91be5)

Open in CodSpeed

@bluetoothbot

bluetoothbot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Previous review — superseded by a newer review below.

@bluetoothbot bluetoothbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@bluetoothbot

Copy link
Copy Markdown
Contributor

PR Review — fix: skip adapter scan for interface lists with no IPv6 entries

Ready to merge. Both suggestions from the previous review are fixed at ebd5138, and nothing new came up.

Strengths:

  • Single adapter scan. ip6_addresses_to_indexes (src/zeroconf/_utils/net.py:128-145) now works out first which entries need adapters (needs_scan) and returns early when there are none. It then calls ifaddr.get_adapters() from one place only. The adapters = None state and the duplicated guards are gone, as suggested before.
  • No behaviour change beyond the fix. Index and IPv6 entries keep their original order and are still handled by the same helpers. An invalid address string still raises ValueError from ipaddress.ip_address, now before the scan instead of after it. That is the same error, just raised sooner.
  • Tests cover every path. test_ip6_addresses_to_indexes_scans_once now uses ["192.168.1.5", "2001:db8::", 1, "fd00:db8::"], so an index and an IPv6 address both come after the first scan. It checks that the scan runs exactly once. The empty list and IPv4-only lists are tested both by calling the function directly and through normalize_interface_choice.
  • The test docstrings are one line each, as CLAUDE.md asks. _utils/net.py is not Cythonized, so no .pxd change is needed.

Previous findings:

  • Suggestion 1 (the lazy-scan guard was repeated): fixed by the needs_scan refactor.
  • Suggestion 2 (no test for an IPv6 address after the scan): fixed by the reordered mixed-list test.

✅ Resolved since last review (2)

Previously-flagged issues verified fixed
  • src/zeroconf/_utils/net.py:130 Lazy adapter scan is repeated in both branches
  • tests/utils/test_net.py:129 Scan-once test leaves the IPv6-after-scan path untested


Checklist

  • Correctness: behavior preserved for index/IPv6 entries
  • Untested branches introduced by the change
  • Structural quality / no duplicated logic
  • Edge cases (empty list, IPv4-only list, invalid address)
  • No public API or Cython .pxd changes required
  • PR description matches diff

Automated review by Kōan (Claude) HEAD=ebd5138 18s

@bluetoothbot bluetoothbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tip

No blocking issues found — ready to merge.

@bdraco

bdraco commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

merged after pypi outage clears

@bdraco
bdraco merged commit 47ec4ba into master Sep 28, 2026
39 checks passed
@bdraco
bdraco deleted the skip-adapter-scan-ipv4-list branch September 28, 2026 14:21
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.

Explicit interface list scans adapters even when it has no IPv6 entries

2 participants