]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127655: Ensure `_SelectorSocketTransport.writelines` pauses the protocol if needed...
authorJ. Nick Koston <nick@koston.org>
Fri, 6 Dec 2024 04:33:03 +0000 (22:33 -0600)
committerGitHub <noreply@github.com>
Fri, 6 Dec 2024 04:33:03 +0000 (10:03 +0530)
Ensure `_SelectorSocketTransport.writelines` pauses the protocol if it reaches the high water mark as needed.

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Lib/asyncio/selector_events.py
Lib/test/test_asyncio/test_selector_events.py
Misc/NEWS.d/next/Security/2024-12-05-21-35-19.gh-issue-127655.xpPoOf.rst [new file with mode: 0644]

index f94bf10b4225e79cdb9fe5437510f84b5ad983f3..f1ab9b12d69a5d8037f1a3ba9856f6141a491f67 100644 (file)
@@ -1175,6 +1175,7 @@ class _SelectorSocketTransport(_SelectorTransport):
         # If the entire buffer couldn't be written, register a write handler
         if self._buffer:
             self._loop._add_writer(self._sock_fd, self._write_ready)
+            self._maybe_pause_protocol()
 
     def can_write_eof(self):
         return True
index aaeda33dd0c677fb0cdcbfedd438b38128a0b990..efca30f37414f95db3cd7fc271d67f48058bfb19 100644 (file)
@@ -805,6 +805,18 @@ class SelectorSocketTransportTests(test_utils.TestCase):
         self.assertTrue(self.sock.send.called)
         self.assertTrue(self.loop.writers)
 
+    def test_writelines_pauses_protocol(self):
+        data = memoryview(b'data')
+        self.sock.send.return_value = 2
+        self.sock.send.fileno.return_value = 7
+
+        transport = self.socket_transport()
+        transport._high_water = 1
+        transport.writelines([data])
+        self.assertTrue(self.protocol.pause_writing.called)
+        self.assertTrue(self.sock.send.called)
+        self.assertTrue(self.loop.writers)
+
     @unittest.skipUnless(selector_events._HAS_SENDMSG, 'no sendmsg')
     def test_write_sendmsg_full(self):
         data = memoryview(b'data')
diff --git a/Misc/NEWS.d/next/Security/2024-12-05-21-35-19.gh-issue-127655.xpPoOf.rst b/Misc/NEWS.d/next/Security/2024-12-05-21-35-19.gh-issue-127655.xpPoOf.rst
new file mode 100644 (file)
index 0000000..76cfc58
--- /dev/null
@@ -0,0 +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`.