[Python-checkins] [3.11] [3.12] GH-106684: Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (GH-107656) (#107836)

kumaraditya303 webhook-mailer at python.org
Thu Aug 10 06:44:35 EDT 2023


https://github.com/python/cpython/commit/fb08b7905eaf67902a89eeec0f8c1aa5ee0c7ea5
commit: fb08b7905eaf67902a89eeec0f8c1aa5ee0c7ea5
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: kumaraditya303 <kumaraditya at python.org>
date: 2023-08-10T16:14:31+05:30
summary:

[3.11] [3.12] GH-106684:  Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (GH-107656) (#107836)

[3.12] GH-106684:  Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not closed by application (GH-107650) (GH-107656)

GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650)
(cherry picked from commit 41178e41995992bbe417f94bce158de93f9e3188)

(cherry picked from commit 7853c769067699c79c0d4fe4967e9d8f8b8b0a5e)

Co-authored-by: Kumar Aditya <kumaraditya at python.org>

files:
A Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst
M Lib/asyncio/streams.py

diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index 560ad8a8510e5..3d577f127041a 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -391,6 +391,10 @@ async def start_tls(self, sslcontext, *,
         self._transport = new_transport
         protocol._replace_writer(self)
 
+    def __del__(self):
+        if not self._transport.is_closing():
+            self.close()
+
 
 class StreamReader:
 
diff --git a/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst b/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst
new file mode 100644
index 0000000000000..85bce76229853
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst
@@ -0,0 +1 @@
+Close :class:`asyncio.StreamWriter` when it is not closed by application leading to memory leaks. Patch by Kumar Aditya.



More information about the Python-checkins mailing list