René's URL Explorer Experiment


Title: bpo-29870: ssl socket leak by misg · Pull Request #981 · python/cpython · GitHub

Open Graph Title: bpo-29870: ssl socket leak by misg · Pull Request #981 · python/cpython

X Title: bpo-29870: ssl socket leak by misg · Pull Request #981 · python/cpython

Description: I'm using Python 3.6 and aiohttp 2.0.5. Given this server: import http.server import ssl addr = ('localhost', 8081) httpd = http.server.HTTPServer(addr, http.server.SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='server.key', certfile='server.cert', server_side=True) httpd.serve_forever() and this client (that basically sends get requests to the above server): import asyncio import aiohttp import resource last = 0 def handler(*_): global last mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024 print('Variation:', mem - last) last = mem async def get(session): response = await session.request('get', 'https://0.0.0.0:8081') # https (ssl) print(response.status) response.close() async def main(loop): conn = aiohttp.TCPConnector(verify_ssl=False, enable_cleanup_closed=True) session = aiohttp.ClientSession(loop=loop, connector=conn) for x in range(500): await get(session) await asyncio.sleep(1, loop=loop) handler() session.close() if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(main(loop)) I have been able to reproduce the issue. In fact, every 6-7 get requests, I got a Variation: 0.25 printed on my screen that indicates my client uses 0.25 more MB of memory (it just grows indefinitely, I tested it with 10000 requests). Using ipdb and objgraph led me to this graph where you can clearly see that there are some circular references between SSLProtocol and _SSLPipe objects: I know that since PEP 442 it shouldn't be a problem anymore, the python garbage collector doesn't care about the cycle and collect them anyway. But the interesting fact is that breaking this cycle (see my commit) actually fixes the memory leak in my client (no more Variation: 0.25, just always Variation: 0.0). My hypothesis is that circular references between SSLProtocol and _SSLPipe actually hide some circular references between some C objects (that define some tp_dealloc slots), that lead to these memory leaks.

Open Graph Description: I'm using Python 3.6 and aiohttp 2.0.5. Given this server: import http.server import ssl addr = ('localhost', 8081) httpd = http.server.HTTPServer(addr, http.server.SimpleHTTPRequestHa...

X Description: I'm using Python 3.6 and aiohttp 2.0.5. Given this server: import http.server import ssl addr = ('localhost', 8081) httpd = http.server.HTTPServer(addr, http.server.SimpleH...

Opengraph URL: https://github.com/python/cpython/pull/981

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:670e9d5c-30ad-ce5d-1024-727fc0ed9e62
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idBD9C:197DA8:208F00:2B2B1D:6A595504
html-safe-nonce0d15a739a56fcc4e5993c4c59cd646d7e314cd4127ffa4f5c8cd7a41c790e9cc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDlDOjE5N0RBODoyMDhGMDA6MkIyQjFEOjZBNTk1NTA0IiwidmlzaXRvcl9pZCI6IjE3MTQ4MTg3OTY1NjYxNzIyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac0d0e1494958b72768d679bf815818dc42b2b80a5eb90b1be1002ec443c114bb7
hovercard-subject-tagpull_request:113978794
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/cpython/pull/981/files
twitter:imagehttps://avatars.githubusercontent.com/u/9290766?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/9290766?s=400&v=4
og:image:altI'm using Python 3.6 and aiohttp 2.0.5. Given this server: import http.server import ssl addr = ('localhost', 8081) httpd = http.server.HTTPServer(addr, http.server.SimpleHTTPRequestHa...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonea540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release5f35ad1fb16417d6e6774c537b62a2fe92222907
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/981/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F981%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F981%2Ffiles
Sign up https://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%2Fcpython
Reloadhttps://github.com/python/cpython/pull/981/files
Reloadhttps://github.com/python/cpython/pull/981/files
Reloadhttps://github.com/python/cpython/pull/981/files
Please reload this pagehttps://github.com/python/cpython/pull/981/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/981/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 34.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
1st1https://github.com/1st1
python:masterhttps://github.com/python/cpython/tree/master
misg:asyncio-sslproto-finalizehttps://github.com/misg/cpython/tree/asyncio-sslproto-finalize
Conversation 9 https://github.com/python/cpython/pull/981
Commits 1 https://github.com/python/cpython/pull/981/commits
Checks 0 https://github.com/python/cpython/pull/981/checks
Files changed https://github.com/python/cpython/pull/981/files
Please reload this pagehttps://github.com/python/cpython/pull/981/files
bpo-29870: ssl socket leak https://github.com/python/cpython/pull/981/files#top
Show all changes 1 commit https://github.com/python/cpython/pull/981/files
bc7b8d4 Break circular references when closing SSLTransport objects misg Apr 3, 2017 https://github.com/python/cpython/pull/981/commits/bc7b8d4d75462c0f9fb2e42dac17d2e3c709d67b
Clear filters https://github.com/python/cpython/pull/981/files
Please reload this pagehttps://github.com/python/cpython/pull/981/files
Please reload this pagehttps://github.com/python/cpython/pull/981/files
Lib/asyncio/sslproto.pyhttps://github.com/python/cpython/pull/981/files#diff-0ae38bdc337cc724282d20111dc780b8a9c07385c80476cf304d5b3c9ec306ec
View file https://github.com/misg/cpython/blob/bc7b8d4d75462c0f9fb2e42dac17d2e3c709d67b/Lib/asyncio/sslproto.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/981/{{ revealButtonHref }}
https://github.com/python/cpython/pull/981/files#diff-0ae38bdc337cc724282d20111dc780b8a9c07385c80476cf304d5b3c9ec306ec
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.