From: Min RK Date: Thu, 1 Aug 2019 11:53:56 +0000 (+0200) Subject: avoid premature _check_closed in _start_read X-Git-Tag: v6.0.4^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=449e04231f3a8b85ed3c5e509e4014e4e4bee3b2;p=thirdparty%2Ftornado.git avoid premature _check_closed in _start_read _start_read can resolve with _try_inline_read, which can succeed even if the stream has been closed if the buffer has been populated by a prior read preserve the fix for asserts being hit when dealing with closed sockets --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 37aeb94f2..267a6c04b 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -799,8 +799,11 @@ class BaseIOStream(object): self._read_from_buffer(pos) def _start_read(self) -> Future: - self._check_closed() # Before reading, check that stream is not closed. - assert self._read_future is None, "Already reading" + if self._read_future is not None: + # raise StreamClosedError instead of assert + # in case of starting a second read after the stream is closed + self._check_closed() + assert self._read_future is None, "Already reading" self._read_future = Future() return self._read_future