[Python-checkins] [3.7] bpo-37279: Fix asyncio sendfile support when extra data are sent in fallback mode. (GH-14075). (GH-14103)

Andrew Svetlov webhook-mailer at python.org
Sat Jun 15 07:56:31 EDT 2019


https://github.com/python/cpython/commit/e5d67f1e31381d28b24f6e1c0f8388d9bf0bfc5f
commit: e5d67f1e31381d28b24f6e1c0f8388d9bf0bfc5f
branch: 3.7
author: Andrew Svetlov <andrew.svetlov at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-06-15T14:56:27+03:00
summary:

[3.7] bpo-37279: Fix asyncio sendfile support when  extra data are sent in fallback mode. (GH-14075). (GH-14103)

(cherry picked from commit ef2152354f03a165c5e3adb53e2276934fabd50a)

Co-authored-by: Andrew Svetlov <andrew.svetlov at gmail.com>

files:
A Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst
M Lib/asyncio/base_events.py
M Lib/test/test_asyncio/test_events.py

diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index a9660ca1089c..52134372fa9f 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -827,7 +827,7 @@ def _getaddrinfo_debug(self, host, port, family, type, proto, flags):
                 read = await self.run_in_executor(None, file.readinto, view)
                 if not read:
                     break  # EOF
-                await self.sock_sendall(sock, view)
+                await self.sock_sendall(sock, view[:read])
                 total_sent += read
             return total_sent
         finally:
@@ -1082,7 +1082,7 @@ def _check_sendfile_params(self, sock, file, offset, count):
                 if not read:
                     return total_sent  # EOF
                 await proto.drain()
-                transp.write(view)
+                transp.write(view[:read])
                 total_sent += read
         finally:
             if total_sent > 0 and hasattr(file, 'seek'):
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 9466111b8ef7..d2c1d7c8a671 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -2117,7 +2117,8 @@ def test_subprocess_shell_invalid_args(self):
 
 class SendfileBase:
 
-    DATA = b"SendfileBaseData" * (1024 * 8)  # 128 KiB
+    # 128 KiB plus small unaligned to buffer chunk
+    DATA = b"SendfileBaseData" * (1024 * 8 + 1)
 
     # Reduce socket buffer size to test on relative small data sets.
     BUF_SIZE = 4 * 1024   # 4 KiB
diff --git a/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst b/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst
new file mode 100644
index 000000000000..d740b9b62b08
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-06-14-13-25-56.bpo-37279.OHlW6l.rst
@@ -0,0 +1,2 @@
+Fix asyncio sendfile support when sendfile sends extra data in fallback
+mode.



More information about the Python-checkins mailing list