Skip to content

fix: fix core reliability, concurrency, and performance issues#1795

Open
roshhellwett wants to merge 8 commits into
python-zeroconf:masterfrom
roshhellwett:master
Open

fix: fix core reliability, concurrency, and performance issues#1795
roshhellwett wants to merge 8 commits into
python-zeroconf:masterfrom
roshhellwett:master

Conversation

@roshhellwett

Copy link
Copy Markdown
  • Pin Cython to 3.2.5 in pyproject.toml to resolve native build failures.
  • Resolve syntax error in _logger.py module docstring.
  • Optimize ServiceRegistry by migrating server and type storage from lists to dicts, enabling O(1) removals and preventing CPU spikes under load.
  • Harden RecordManager by utilizing set.discard() to avoid KeyError crashes during asynchronous listener removal.
  • Fix robustness: cache mutates shared DNSRecord instances in place to expire TTL #1780: Stop in-place mutation of cached DNSRecord TTLs to prevent shared state corruption across event loop listeners.
  • Update tests to accommodate cache architectural changes and resolve iterator mutations.

roshhellwett and others added 2 commits June 16, 2026 12:51
- Pin Cython to 3.2.5 in pyproject.toml to resolve native build failures.
- Resolve syntax error in _logger.py module docstring.
- Optimize ServiceRegistry by migrating server and type storage from lists to dicts, enabling O(1) removals and preventing CPU spikes under load.
- Harden RecordManager by utilizing set.discard() to avoid KeyError crashes during asynchronous listener removal.
- Fix python-zeroconf#1780: Stop in-place mutation of cached DNSRecord TTLs to prevent shared state corruption across event loop listeners.
- Update tests to accommodate cache architectural changes and resolve iterator mutations.
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.80%. Comparing base (d68897b) to head (8256986).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1795      +/-   ##
==========================================
+ Coverage   99.77%   99.80%   +0.02%     
==========================================
  Files          33       33              
  Lines        3536     3549      +13     
  Branches      498      504       +6     
==========================================
+ Hits         3528     3542      +14     
+ Misses          5        4       -1     
  Partials        3        3              

☔ 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.

@roshhellwett roshhellwett changed the title Fix core reliability, concurrency, and performance issues fix: fix core reliability, concurrency, and performance issues Jun 16, 2026
@roshhellwett roshhellwett reopened this Jun 16, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing roshhellwett:master (8256986) with master (d68897b)

Open in CodSpeed

- Add type hints using cast to resolve mypy typing issues in test modules

- Ensure 100% codecov branch coverage by ignoring unreachable fallback paths

- Fix code formatting and imports flagged by pre-commit tools

- Update auto-generated setup.py to ignore flake8/ruff formatting
- Fix ServiceRegistry cython type mismatch where record_list was typed as cython.list instead of cython.dict, causing TypeErrors in Linux native cython builds after migrating server and type storage to dicts.
@roshhellwett

Copy link
Copy Markdown
Author

@bdraco This PR is now fully ready for review!

A quick summary of the fixes included:

ServiceRegistry Optimization: Migrated types and servers memory structures from list to dict to guarantee $O(1)$ removals and avoid CPU spikes under heavy load.
Cache Hardening: Replaced in-place mutations of shared DNSRecord instances with immutable replacements to prevent shared state corruption and TTL expirations bleeding across cache boundaries (Resolves #1780).
Cython Compatibility: Fixed a lingering cython.list declaration in @cython.locals inside registry.pxd that was previously causing TypeError: Expected list, got dict crashes during the native Linux cython test builds.
Test Coverage & Typing: Cleaned up mypy strict typing errors using explicit typing.cast() for the new cache structure, and ensured codecov/patch remains at 100%.
All 35 CI checks (including native Cython extensions across all Python matrix versions) are now successfully passing. Let me know if you need any additional changes prior to merging!

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.

robustness: cache mutates shared DNSRecord instances in place to expire TTL

1 participant