René's URL Explorer Experiment


Title: Socket leak when opening, and closing sockets · Issue #1589 · python-zeroconf/python-zeroconf · GitHub

Open Graph Title: Socket leak when opening, and closing sockets · Issue #1589 · python-zeroconf/python-zeroconf

X Title: Socket leak when opening, and closing sockets · Issue #1589 · python-zeroconf/python-zeroconf

Description: Even though #171 and the subsequent fix in PR #188/270 addressed one class of socket leaks, we’re still seeing file-descriptor leaks when creating and tearing down Zeroconf instances in rapid succession (e.g. one per “cycle”). Over time,...

Open Graph Description: Even though #171 and the subsequent fix in PR #188/270 addressed one class of socket leaks, we’re still seeing file-descriptor leaks when creating and tearing down Zeroconf instances in rapid succe...

X Description: Even though #171 and the subsequent fix in PR #188/270 addressed one class of socket leaks, we’re still seeing file-descriptor leaks when creating and tearing down Zeroconf instances in rapid succe...

Opengraph URL: https://github.com/python-zeroconf/python-zeroconf/issues/1589

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Socket leak when opening, and closing sockets","articleBody":"Even though https://github.com/jstasiak/python-zeroconf/issues/171 and the subsequent fix in PR #188/270 addressed one class of socket leaks, we’re still seeing file-descriptor leaks when creating and tearing down Zeroconf instances in rapid succession (e.g. one per “cycle”). Over time, the process exhausts its FD limit with errors like OSError: [Errno 24] Too many open files.\nWhat’s happening\n\nPersistent sockets remain open\nEvery time Zeroconf(interfaces=[…]) is called, it creates a set of listening and responding sockets. Although those sockets are closed (via .close()) when the instance is torn down, some underlying file descriptors remain open in the OS.\n\nLingering asyncio selectors and threads\nThe library spins up an asyncio event loop per instance. Even after .close(), we observe threads (in selector_events.py and _core.py) that never fully tear down, holding onto their self-pipes or sockets.\n\nifaddr adapter enumeration leak\nIn our environment, each new Zeroconf triggers an ifaddr.get_adapters() call—which under certain Linux distributions seems to leave open netlink sockets or file handles that are never garbage-collected.\n\n\nReproduction steps\n\nWrite a simple loop that does:\n\n```python\nfrom zeroconf import Zeroconf\nimport time\nimport os\n\n# Run a tight loop creating \u0026 closing Zeroconf instances\nfor i in range(1, 1001):\n    zc = Zeroconf(interfaces=['127.0.0.1'])\n    zc.close()\n    if i % 100 == 0:\n        print(f\"Iteration {i}\")\n        time.sleep(0.1)  # give the OS a moment\n\ndef fd_count():\n    return len(os.listdir(f\"/proc/{os.getpid()}/fd\"))\n\nfor i in range(1,1001):\n    zc = Zeroconf(interfaces=['127.0.0.1'])\n    zc.close()\n    if i % 100 == 0:\n        print(f\"Iteration {i}, open-fds: {fd_count()}\")\n```\n\n\nExpected behavior\n\nAfter zc.close(), all sockets, event loops, and threads associated with that Zeroconf instance should be fully torn down, and the OS file descriptor count should return to its prior level.\n\n\nEnvironment\n\npython-zeroconf version: ≥ 0.28.0 (includes the fixes from PR #188/270)\nOS: Ubuntu 24.04, Linux kernel 6.x\nPython: 3.12\n\n\nSuggested investigation areas\n\n- Verify that every internal selector and asyncio loop is explicitly closed and that its underlying sockets/pipes are closed too.\n- Audit ifaddr.get_adapters() and its use of netlink sockets—ensure that any sockets opened for adapter enumeration are closed.\n- Add a regression test that repeatedly constructs and closes Zeroconf objects and asserts that FD count remains constant.\n\n\n\nI'm trying to write a unidirectional mDNS reflector solution, it works flawlessly if I start, and then stop the main reflector script rather than simply closing the sockets, but this requires a wrapper script to then handle this with added complexity along with added noise \u0026 advertisements appearing, then disappearing when the reflector script exits.\n\n\nUnfortunately, I don't know enough to patch this, and implement a fix effectively, I've been fault finding with the use of AI to be able to get this write up where it is so there could be some incorrect information, but running the code above I can re-produce the issue on different systems.\n\nIf you need any help testing, I'd be happy to assist where I can","author":{"url":"https://github.com/brayden-b-LA","@type":"Person","name":"brayden-b-LA"},"datePublished":"2025-05-25T09:42:52.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1589/python-zeroconf/issues/1589"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e84cfed3-2ffd-4fd3-e3aa-8e76bd2d6853
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAFBA:63CEC:18102C5:2090E83:6972B30D
html-safe-nonceb6ba650d60c2b0cc75df2f6804ed458abd7082b0d8f2ab1d5d08c5f84b973624
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkJBOjYzQ0VDOjE4MTAyQzU6MjA5MEU4Mzo2OTcyQjMwRCIsInZpc2l0b3JfaWQiOiI3ODQ4NjQzODcxNTAyNDE0NjA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmaca8e89182c1b332532817626adc47a8f537240dfd2c9a8f155501eb097985ba5f
hovercard-subject-tagissue:3089177103
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-zeroconf/python-zeroconf/1589/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2dc48458cdec499d751fecc55aaaaa9eb2b526875993bd5d139bbd9569ce17d8/python-zeroconf/python-zeroconf/issues/1589
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2dc48458cdec499d751fecc55aaaaa9eb2b526875993bd5d139bbd9569ce17d8/python-zeroconf/python-zeroconf/issues/1589
og:image:altEven though #171 and the subsequent fix in PR #188/270 addressed one class of socket leaks, we’re still seeing file-descriptor leaks when creating and tearing down Zeroconf instances in rapid succe...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebrayden-b-LA
hostnamegithub.com
expected-hostnamegithub.com
None51c0d0848f5569c6fa2198e9d69bd5f8f94a83c9fa3659e40728e7732afab130
turbo-cache-controlno-preview
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
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release10c5e2f2307495b2750073db87e9a5d3356a924f
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues/1589#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2F1589
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-zeroconf%2Fpython-zeroconf%2Fissues%2F1589
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-zeroconf%2Fpython-zeroconf
Reloadhttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues/1589
Reloadhttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues/1589
Reloadhttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues/1589
python-zeroconf https://patch-diff.githubusercontent.com/python-zeroconf
python-zeroconfhttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-zeroconf%2Fpython-zeroconf
Fork 232 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-zeroconf%2Fpython-zeroconf
Star 704 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-zeroconf%2Fpython-zeroconf
Code https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf
Issues 50 https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues
Pull requests 5 https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/pulls
Discussions https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/discussions
Actions https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/actions
Projects 0 https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/projects
Wiki https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/wiki
Security 0 https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/security
Insights https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/pulse
Code https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf
Issues https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues
Pull requests https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/pulls
Discussions https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/discussions
Actions https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/actions
Projects https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/projects
Wiki https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/wiki
Security https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/security
Insights https://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-zeroconf/python-zeroconf/issues/1589
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-zeroconf/python-zeroconf/issues/1589
Socket leak when opening, and closing socketshttps://patch-diff.githubusercontent.com/python-zeroconf/python-zeroconf/issues/1589#top
https://github.com/brayden-b-LA
https://github.com/brayden-b-LA
brayden-b-LAhttps://github.com/brayden-b-LA
on May 25, 2025https://github.com/python-zeroconf/python-zeroconf/issues/1589#issue-3089177103
#171https://github.com/python-zeroconf/python-zeroconf/issues/171
#188https://github.com/python-zeroconf/python-zeroconf/pull/188
#188https://github.com/python-zeroconf/python-zeroconf/pull/188
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.