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
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:670e9d5c-30ad-ce5d-1024-727fc0ed9e62 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | BD9C:197DA8:208F00:2B2B1D:6A595504 |
| html-safe-nonce | 0d15a739a56fcc4e5993c4c59cd646d7e314cd4127ffa4f5c8cd7a41c790e9cc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDlDOjE5N0RBODoyMDhGMDA6MkIyQjFEOjZBNTk1NTA0IiwidmlzaXRvcl9pZCI6IjE3MTQ4MTg3OTY1NjYxNzIyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 0d0e1494958b72768d679bf815818dc42b2b80a5eb90b1be1002ec443c114bb7 |
| hovercard-subject-tag | pull_request:113978794 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/981/files |
| twitter:image | https://avatars.githubusercontent.com/u/9290766?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/9290766?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | a540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 5f35ad1fb16417d6e6774c537b62a2fe92222907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width