René's URL Explorer Experiment


Title: fix: bound duplicate-packet dedup against alternating-payload floods by bdraco · Pull Request #1750 · python-zeroconf/python-zeroconf · GitHub

Open Graph Title: fix: bound duplicate-packet dedup against alternating-payload floods by bdraco · Pull Request #1750 · python-zeroconf/python-zeroconf

X Title: fix: bound duplicate-packet dedup against alternating-payload floods by bdraco · Pull Request #1750 · python-zeroconf/python-zeroconf

Description: Summary Single-slot dedup in _process_datagram_at_time only compared against self.data; alternating two byte-distinct payloads (A, B, A, B, ...) slipped past on every packet, forcing every datagram through DNSIncoming parse and the deferred-queue scan. This adds a bounded per-listener recency window so the alternating-flood case is caught while keeping the same-packet fast path on the original code path. Details _process_datagram_at_time keeps the existing self.data == data single-slot check as the fast path so the steady-state same-payload hit stays a pure-C compare; on miss it consults a bounded _recent_packets: dict[bytes, float] keyed on payload bytes. recent_packets.get(data, 0.0) paired with (now - _DUPLICATE_PACKET_SUPPRESSION_INTERVAL) < recent_time keeps the suppression compare a single C double compare under Cython; stored values are millisecond timestamps so 0.0 never collides with a real entry. Only payloads without a QU question are cached so unicast replies still go out on every receipt; the dict path therefore does not re-check has_qu_question on hits. State lives on each AsyncListener (one per reader socket / interface) so a duplicate seen on one interface does not suppress a legitimate QU or unicast reply that arrives on another. _RECENT_PACKETS_MAX is added to const.py and cdef'd in _listener.pxd; eviction uses dict insertion order via next(iter(recent_packets)) so the oldest entry is dropped when the window is full. tests/_clear_cache now also resets _recent_packets and the single-slot state; tests that clear the cache between phases get a fresh listener view so legitimate retransmits inside the suppression window are not caught by the previous phase's window. Fixes #1724. Test plan SKIP_CYTHON=1 poetry run pytest tests/ --no-cov --timeout=60 -- 368 passed. REQUIRE_CYTHON=1 poetry install --only=main,dev && poetry run pytest tests/ --no-cov --timeout=60 -- 368 passed. New tests in tests/test_listener.py: test_guard_against_alternating_duplicate_packets -- pins the alternating-flood guard. test_recent_packets_window_is_bounded -- pins eviction of the oldest entries once the window fills. Existing test_guard_against_duplicate_packets updated to assert bounded-window semantics where the old assertions encoded the single-slot bypass. poetry run cython -a -3 src/zeroconf/_listener.py -- the hit-path compare on line 145 stays score-0 (pure C double compare); the dict.get on line 144 is score-15 (__Pyx_PyDict_GetItemDefault + PyFloat_AsDouble). Local steady-state timings on the tests/benchmarks/test_listener_dedup.py shapes vs master, 200 iters x 1000 runs: test_dedup_hit_same_payload: 6.4 us vs 6.4 us on master (no regression; fast path preserved). test_alternating_payloads: 8.7 us vs 78 us on master (~9x improvement; the issue). test_unique_payloads: 93 us vs 75 us on master (~90 ns per packet for the bounded-window bookkeeping).

Open Graph Description: Summary Single-slot dedup in _process_datagram_at_time only compared against self.data; alternating two byte-distinct payloads (A, B, A, B, ...) slipped past on every packet, forcing every datagram...

X Description: Summary Single-slot dedup in _process_datagram_at_time only compared against self.data; alternating two byte-distinct payloads (A, B, A, B, ...) slipped past on every packet, forcing every datagram...

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

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:41c6c523-b4fb-7754-6867-7aba3d2dbe71
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idC162:2433F1:18244B:209BFE:6B008336
html-safe-noncef7a0f83eaa32df87434753dcd3353fce711ee513d893e5ea5074633a2f45eadf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTYyOjI0MzNGMToxODI0NEI6MjA5QkZFOjZCMDA4MzM2IiwidmlzaXRvcl9pZCI6IjcxOTk4MzA4MTc0MTYxODQ2MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaccd4452a1ad1b59ff68a2216fc5a973ceccab0dc45cec6b0ae98490136294f129
hovercard-subject-tagpull_request:3716619915
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/1750/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:altSummary Single-slot dedup in _process_datagram_at_time only compared against self.data; alternating two byte-distinct payloads (A, B, A, B, ...) slipped past on every packet, forcing every datagram...
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/1750/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fpull%2F1750%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%2F1750%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/1750/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
Reloadhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/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
fix/bounded-dedup-recency-windowhttps://github.com/python-zeroconf/python-zeroconf/tree/fix/bounded-dedup-recency-window
Conversation 11 https://github.com/python-zeroconf/python-zeroconf/pull/1750
Commits 1 https://github.com/python-zeroconf/python-zeroconf/pull/1750/commits
Checks 35 https://github.com/python-zeroconf/python-zeroconf/pull/1750/checks
Files changed https://github.com/python-zeroconf/python-zeroconf/pull/1750/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
fix: bound duplicate-packet dedup against alternating-payload floods https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#top
Show all changes 1 commit https://github.com/python-zeroconf/python-zeroconf/pull/1750/files
56bb3a8 fix: bound duplicate-packet dedup against alternating-payload floods bdraco May 20, 2026 https://github.com/python-zeroconf/python-zeroconf/pull/1750/commits/56bb3a80fe2a23ddad815e7bc773212220c9e66a
Clear filters https://github.com/python-zeroconf/python-zeroconf/pull/1750/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
_listener.pxd https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
_listener.py https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
const.py https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
__init__.py https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-001e61d97d9dee27d0c5aa1f23ba6c1972cd8a2e8320bac839656b0ab935b84d
test_handlers.py https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
test_listener.py https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-19b2f8112118f7597bd34eb1327f706bd5c20bd7b300a1dd787a3e3cfc64dd7c
src/zeroconf/_listener.pxdhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/src/zeroconf/_listener.pxd
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-bff2b43c81cd5dc78e524ed6cd0a7c8cef9ad4cd2410097ad3b4cd20f73f589a
src/zeroconf/_listener.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/src/zeroconf/_listener.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-482d92e649d0a9dfb6f7434c0ec1854490aeda07f86f21ac36e348a9ad1ab4d2
src/zeroconf/const.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/src/zeroconf/const.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-2925fab357e035f1e0cb51ebce6d44e682392bccd5b6b5809dc1f5ea78d6d9b4
tests/__init__.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-001e61d97d9dee27d0c5aa1f23ba6c1972cd8a2e8320bac839656b0ab935b84d
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/tests/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-001e61d97d9dee27d0c5aa1f23ba6c1972cd8a2e8320bac839656b0ab935b84d
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-001e61d97d9dee27d0c5aa1f23ba6c1972cd8a2e8320bac839656b0ab935b84d
tests/test_handlers.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/tests/test_handlers.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-a80edd2ae6b30f0f5a2a8f7bdd4089a43fc5dca4d21588fa4879392950b609f1
tests/test_listener.pyhttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-19b2f8112118f7597bd34eb1327f706bd5c20bd7b300a1dd787a3e3cfc64dd7c
View file https://github.com/python-zeroconf/python-zeroconf/blob/56bb3a80fe2a23ddad815e7bc773212220c9e66a/tests/test_listener.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python-zeroconf/python-zeroconf/pull/1750/{{ revealButtonHref }}
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-19b2f8112118f7597bd34eb1327f706bd5c20bd7b300a1dd787a3e3cfc64dd7c
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-19b2f8112118f7597bd34eb1327f706bd5c20bd7b300a1dd787a3e3cfc64dd7c
https://github.com/python-zeroconf/python-zeroconf/pull/1750/files#diff-19b2f8112118f7597bd34eb1327f706bd5c20bd7b300a1dd787a3e3cfc64dd7c
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/files
Please reload this pagehttps://github.com/python-zeroconf/python-zeroconf/pull/1750/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.