Skip to content

Commit

Permalink
pythongh-90467: StreamReaderProtocol - add strong reference to create…
Browse files Browse the repository at this point in the history
…d task (pythonGH-96323)

(cherry picked from commit e860e52)

Co-authored-by: Kirill <iam@python273.pw>
  • Loading branch information
python273 authored and miss-islington committed Aug 27, 2022
1 parent 103f26f commit c98a665
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Lib/asyncio/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def __init__(self, stream_reader, client_connected_cb=None, loop=None):
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
Expand Down Expand Up @@ -248,7 +249,7 @@ def connection_made(self, transport):
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):
Expand All @@ -266,6 +267,7 @@ def connection_lost(self, exc):
super().connection_lost(exc)
self._stream_reader_wr = None
self._stream_writer = None
self._task = None
self._transport = None

def data_received(self, data):
Expand Down
2 changes: 2 additions & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ Ram Rachum
Jeffrey Rackauckas
Jérôme Radix
Burton Radons
Kirill (python273) R.
Abhilash Raj
Shorya Raj
Ajith Ramachandran
Expand Down Expand Up @@ -1981,6 +1982,7 @@ Gordon Worley
Darren Worrall
Thomas Wouters
Daniel Wozniak
Simon Wrede
Marcin Niemira
Wei Wu
Heiko Wundram
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c98a665

Please sign in to comment.