gh-114914: Avoid keeping dead StreamWriter alive by CendioOssman · Pull Request #115661 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Lib/asyncio/streams.py
25 changes: 25 additions & 0 deletions Lib/test/test_asyncio/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,31 @@ async def inner(httpd):

self.assertEqual(messages, [])

def test_unclosed_server_resource_warnings(self):
async def inner(rd, wr):
fut.set_result(True)
with self.assertWarns(ResourceWarning) as cm:
del wr
gc.collect()
self.assertEqual(len(cm.warnings), 1)
self.assertTrue(str(cm.warnings[0].message).startswith("unclosed <StreamWriter"))
Comment thread
gvanrossum marked this conversation as resolved.

async def outer():
srv = await asyncio.start_server(inner, socket_helper.HOSTv4, 0)
async with srv:
addr = srv.sockets[0].getsockname()
with socket.create_connection(addr):
# Give the loop some time to notice the connection
await fut

messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))

fut = self.loop.create_future()
self.loop.run_until_complete(outer())

self.assertEqual(messages, [])

def _basetest_unhandled_exceptions(self, handle_echo):
port = socket_helper.find_unused_port()

Expand Down