Repository navigation
test_asyncio.test_streams raises a ResourceWarning #116112
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortestsTests in the Lib/test dirTests in the Lib/test dir
on Feb 29, 2024 Bisects to a355f60 CC @CendioOssman
To be precise the error occurs in
test_unhandled_cancel:(.venv) ~/cpython$ ./python.exe -m test test_asyncio.test_streams -v -m test_unhandled_cancel [...] Using random seed: 781240745 0:00:00 load avg: 1.56 Run 1 test sequentially 0:00:00 load avg: 1.56 [1/1] test_asyncio.test_streams test_unhandled_cancel (test.test_asyncio.test_streams.StreamTests.test_unhandled_cancel) ... /Users/guido/cpython/Lib/asyncio/streams.py:410: ResourceWarning: unclosed <StreamWriter transport=<_SelectorSocketTransport closing fd=11 read=idle write=<idle, bufsize=0>> reader=<StreamReader transport=<_SelectorSocketTransport closing fd=11 read=idle write=<idle, bufsize=0>>>> warnings.warn(f"unclosed {self!r}", ResourceWarning) okReacted by sobolevnThanks for letting me know. I'll try to have a look as soon as I'm able.
Reacted by sobolevnIn this case, the
ResourceWarningis absolutely correct. The test does not correctly clean up the streams.I am not sure why the same thing doesn't happen for
test_unhandled_exception(). Maybe theStreamWritergets tangled up in the exception stack and is kept alive?The fix is this:
diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index bf123ebf9b..2cf48538d5 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1188,6 +1188,7 @@ async def handle_echo(reader, writer): def test_unhandled_cancel(self): async def handle_echo(reader, writer): + writer.close() asyncio.current_task().cancel() messages = self._basetest_unhandled_exceptions(handle_echo) self.assertEqual(messages, [])
Can someone easily commit this without a PR song and dance?
Can someone easily commit this without a PR song and dance?
No, this is not possible. All changes require a PR, CI run and proper review.
If you don't have time, I can help you (with crediting your work properly) :)Reacted by Kirill PodoprigoraThat would be appreciated.
Reacted by sobolevnShould be fixed now! Thanks everyone!
Reacted by Kirill Podoprigora
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
ResourceWarningintest_asyncio.test_stream#116371