]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] GH-106684: Close `asyncio.StreamWriter` when `asyncio.StreamWriter` is not...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 10 Aug 2023 09:24:22 +0000 (02:24 -0700)
committerGitHub <noreply@github.com>
Thu, 10 Aug 2023 09:24:22 +0000 (11:24 +0200)
GH-106684: raise `ResourceWarning` when `asyncio.StreamWriter` is not closed (GH-107650)
(cherry picked from commit 41178e41995992bbe417f94bce158de93f9e3188)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Lib/asyncio/streams.py
Misc/NEWS.d/next/Library/2023-08-05-05-10-41.gh-issue-106684.P9zRXb.rst [new file with mode: 0644]

index bf15f517e50dcea50078e4b67d0abd5628b10396..14861dffce3a84d78a167949930e38a456f2cc37 100644 (file)
@@ -392,6 +392,10 @@ class StreamWriter:
         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 (file)
index 0000000..85bce76
--- /dev/null
@@ -0,0 +1 @@
+Close :class:`asyncio.StreamWriter` when it is not closed by application leading to memory leaks. Patch by Kumar Aditya.