]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90467: StreamReaderProtocol - add strong reference to created task (GH-96323)...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 30 Aug 2022 10:59:32 +0000 (03:59 -0700)
committerGitHub <noreply@github.com>
Tue, 30 Aug 2022 10:59:32 +0000 (11:59 +0100)
(cherry picked from commit e860e521ec0d84e175269aeb15cf24bd6053ad17)

Co-authored-by: Kirill <iam@python273.pw>
Co-authored-by: Kirill <iam@python273.pw>
Lib/asyncio/streams.py
Misc/ACKS
Misc/NEWS.d/next/Library/2022-08-27-14-38-49.gh-issue-90467.VOOB0p.rst [new file with mode: 0644]

index a568c4e4b295f0f11919604f8182e192efe3bf53..af78e6b45881658d5f96a3427a0c5b9398b98d44 100644 (file)
@@ -206,6 +206,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
             self._strong_reader = stream_reader
         self._reject_connection = False
         self._stream_writer = None
+        self._task = None
         self._transport = None
         self._client_connected_cb = client_connected_cb
         self._over_ssl = False
@@ -248,7 +249,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
             res = self._client_connected_cb(reader,
                                             self._stream_writer)
             if coroutines.iscoroutine(res):
-                self._loop.create_task(res)
+                self._task = self._loop.create_task(res)
             self._strong_reader = None
 
     def connection_lost(self, exc):
@@ -266,6 +267,7 @@ class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
         super().connection_lost(exc)
         self._stream_reader_wr = None
         self._stream_writer = None
+        self._task = None
         self._transport = None
 
     def data_received(self, data):
index 6e53d5a7cc4ba373c1be8c8f806c6817a4c85bb9..58b29c19400e873b81b51e98c7b933665ad08a99 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1438,6 +1438,7 @@ Ram Rachum
 Jeffrey Rackauckas
 Jérôme Radix
 Burton Radons
+Kirill (python273) R.
 Abhilash Raj
 Shorya Raj
 Ajith Ramachandran
@@ -1981,6 +1982,7 @@ Gordon Worley
 Darren Worrall
 Thomas Wouters
 Daniel Wozniak
+Simon Wrede
 Marcin Niemira
 Wei Wu
 Heiko Wundram
diff --git a/Misc/NEWS.d/next/Library/2022-08-27-14-38-49.gh-issue-90467.VOOB0p.rst b/Misc/NEWS.d/next/Library/2022-08-27-14-38-49.gh-issue-90467.VOOB0p.rst
new file mode 100644 (file)
index 0000000..282c0e7
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :class:`asyncio.streams.StreamReaderProtocol` to keep a strong reference
+to the created task, so that it's not garbage collected