mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
bpo-26819: Prevent proactor double read on resume (GH-6921)
The proactor event loop has a race condition when reading with
pausing/resuming. `resume_reading()` unconditionally schedules the read
function to read from the current future. If `resume_reading()` was
called before the previously scheduled done callback fires, this results
in two attempts to get the data from the most recent read and an
assertion failure. This commit tracks whether or not `resume_reading`
needs to reschedule the callback to restart the loop, preventing a
second attempt to read the data.
(cherry picked from commit 4151061855
)
Co-authored-by: CtrlZvi <viz+github@flippedperspective.com>
This commit is contained in:
parent
f0af69faee
commit
28ea38b97b
3 changed files with 17 additions and 2 deletions
|
@ -334,7 +334,7 @@ class ProactorSocketTransportTests(test_utils.TestCase):
|
|||
def test_pause_resume_reading(self):
|
||||
tr = self.socket_transport()
|
||||
futures = []
|
||||
for msg in [b'data1', b'data2', b'data3', b'data4', b'']:
|
||||
for msg in [b'data1', b'data2', b'data3', b'data4', b'data5', b'']:
|
||||
f = asyncio.Future(loop=self.loop)
|
||||
f.set_result(msg)
|
||||
futures.append(f)
|
||||
|
@ -364,6 +364,13 @@ class ProactorSocketTransportTests(test_utils.TestCase):
|
|||
self.protocol.data_received.assert_called_with(b'data3')
|
||||
self.loop._run_once()
|
||||
self.protocol.data_received.assert_called_with(b'data4')
|
||||
|
||||
tr.pause_reading()
|
||||
tr.resume_reading()
|
||||
self.loop.call_exception_handler = mock.Mock()
|
||||
self.loop._run_once()
|
||||
self.loop.call_exception_handler.assert_not_called()
|
||||
self.protocol.data_received.assert_called_with(b'data5')
|
||||
tr.close()
|
||||
|
||||
self.assertFalse(tr.is_reading())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue