[3.11] gh-103607: Fix pause_reading to work when called from connection_made in asyncio. (GH-17425) (#103918)

gh-103607: Fix `pause_reading` to work when called from `connection_made` in `asyncio`. (GH-17425)
(cherry picked from commit 78942ecd9b)

Co-authored-by: Itayazolay <itayazolay@gmail.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2023-04-27 03:29:54 -07:00 committed by GitHub
parent 4041251a36
commit 2cd1b9c2ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 24 deletions

View file

@ -482,13 +482,21 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
self._loop.call_soon(self._loop._add_reader,
self._loop.call_soon(self._add_reader,
self._fileno, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self._loop.call_soon(futures._set_result_unless_cancelled,
waiter, None)
def _add_reader(self, fd, callback):
if not self.is_reading():
return
self._loop._add_reader(fd, callback)
def is_reading(self):
return not self._paused and not self._closing
def __repr__(self):
info = [self.__class__.__name__]
if self._pipe is None:
@ -529,7 +537,7 @@ def _read_ready(self):
self._loop.call_soon(self._call_connection_lost, None)
def pause_reading(self):
if self._closing or self._paused:
if not self.is_reading():
return
self._paused = True
self._loop._remove_reader(self._fileno)