GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — asyncio: potential leak of TLS connections · Issue #106684 · python/cpython Closed Labels 3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error DescriptionBug reportSynopsisForgetting to close TLS connections manually with Note: the reference is properly released when the remote side closes the connection This seems to be counter intuitive relative to other python APIs where the connection is closed when the handle goes out of scope Details
When trying to debug this issue I found out that a Example scriptimport os import asyncio import gc import signal HOST = "google.fr" # will keep the connection alive for a few minutes at least async def query(): reader, writer = await asyncio.open_connection(HOST, 443, ssl=True) # No connection: close, remote side will keep the connection open writer.write(f"GET / HTTP/1.1\r\nHost: {HOST}\r\n\r\n".encode()) await writer.drain() # only read the first header line try: return (await reader.readline()).decode() finally: # closing the writer will properly finalize the connection # writer.close() pass # reader and writer are now unreachable async def amain(): await query() # The _SSLProtocolTransport object is kept in memory and the # connection won't be released until the remote side closes the connection for _ in range(200): # Just be sure everything is freed, just in case gc.collect() await asyncio.sleep(1) def main(): print(f"PID {os.getpid()}") task = asyncio.ensure_future(amain()) loop = asyncio.get_event_loop() loop.add_signal_handler(signal.SIGTERM, task.cancel) loop.add_signal_handler(signal.SIGINT, task.cancel) loop.run_until_complete(task) if __name__ == "__main__": main() Your environment
Linked PRs
Activity
MetadataMetadataAssigneesLabels3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-asynciotype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error Projects
MilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |