mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-114914: Avoid keeping dead StreamWriter alive (#115661)
In some cases we might cause a StreamWriter to stay alive even when the application has dropped all references to it. This prevents us from doing automatical cleanup, and complaining that the StreamWriter wasn't properly closed. Fortunately, the extra reference was never actually used for anything so we can just drop it.
This commit is contained in:
parent
686ec17f50
commit
a355f60b03
3 changed files with 31 additions and 10 deletions
|
@ -1130,6 +1130,31 @@ os.close(fd)
|
|||
|
||||
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"))
|
||||
|
||||
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()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue