Skip to content

Commit 71e8429

Browse files
miss-islingtonbdracokumaraditya303
authored
[3.13] gh-127655: Ensure _SelectorSocketTransport.writelines pauses the protocol if needed (GH-127656) (#127663)
gh-127655: Ensure `_SelectorSocketTransport.writelines` pauses the protocol if needed (GH-127656) Ensure `_SelectorSocketTransport.writelines` pauses the protocol if it reaches the high water mark as needed. (cherry picked from commit e991ac8) Co-authored-by: J. Nick Koston <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
1 parent 69bb1c6 commit 71e8429

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/asyncio/selector_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ def writelines(self, list_of_data):
11751175
# If the entire buffer couldn't be written, register a write handler
11761176
if self._buffer:
11771177
self._loop._add_writer(self._sock_fd, self._write_ready)
1178+
self._maybe_pause_protocol()
11781179

11791180
def can_write_eof(self):
11801181
return True

Lib/test/test_asyncio/test_selector_events.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,18 @@ def test_writelines_send_partial(self):
805805
self.assertTrue(self.sock.send.called)
806806
self.assertTrue(self.loop.writers)
807807

808+
def test_writelines_pauses_protocol(self):
809+
data = memoryview(b'data')
810+
self.sock.send.return_value = 2
811+
self.sock.send.fileno.return_value = 7
812+
813+
transport = self.socket_transport()
814+
transport._high_water = 1
815+
transport.writelines([data])
816+
self.assertTrue(self.protocol.pause_writing.called)
817+
self.assertTrue(self.sock.send.called)
818+
self.assertTrue(self.loop.writers)
819+
808820
@unittest.skipUnless(selector_events._HAS_SENDMSG, 'no sendmsg')
809821
def test_write_sendmsg_full(self):
810822
data = memoryview(b'data')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the :class:`!asyncio.selector_events._SelectorSocketTransport` transport not pausing writes for the protocol when the buffer reaches the high water mark when using :meth:`asyncio.WriteTransport.writelines`.

0 commit comments

Comments
 (0)