summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorPierre Ossman (ThinLinc team) <ossman@cendio.se>2024-02-28 01:27:44 (GMT)
committerGitHub <noreply@github.com>2024-02-28 01:27:44 (GMT)
commita355f60b032306651ca27bc53bbb82eb5106ff71 (patch)
tree5d5b332d9ef8ce85501bdf350f06f9d7298388ac /Lib/test/test_asyncio
parent686ec17f506cddd0b14a8aad5849c15ffc20ed46 (diff)
downloadcpython-a355f60b032306651ca27bc53bbb82eb5106ff71.zip
cpython-a355f60b032306651ca27bc53bbb82eb5106ff71.tar.gz
cpython-a355f60b032306651ca27bc53bbb82eb5106ff71.tar.bz2
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.
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_streams.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py
index 2109905..bf123eb 100644
--- a/Lib/test/test_asyncio/test_streams.py
+++ b/Lib/test/test_asyncio/test_streams.py
@@ -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()