Skip to content

Commit bb07321

Browse files
bpo-37279: Fix asyncio sendfile support when extra data are sent in fallback mode. (GH-14075)
(cherry picked from commit ef21523) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
1 parent 3fde750 commit bb07321

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

Lib/asyncio/base_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ async def _sock_sendfile_fallback(self, sock, file, offset, count):
861861
read = await self.run_in_executor(None, file.readinto, view)
862862
if not read:
863863
break # EOF
864-
await self.sock_sendall(sock, view)
864+
await self.sock_sendall(sock, view[:read])
865865
total_sent += read
866866
return total_sent
867867
finally:
@@ -1145,7 +1145,7 @@ async def _sendfile_fallback(self, transp, file, offset, count):
11451145
if not read:
11461146
return total_sent # EOF
11471147
await proto.drain()
1148-
transp.write(view)
1148+
transp.write(view[:read])
11491149
total_sent += read
11501150
finally:
11511151
if total_sent > 0 and hasattr(file, 'seek'):

Lib/test/test_asyncio/test_sendfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ async def wait_closed(self):
8686

8787
class SendfileBase:
8888

89-
DATA = b"SendfileBaseData" * (1024 * 8) # 128 KiB
89+
# 128 KiB plus small unaligned to buffer chunk
90+
DATA = b"SendfileBaseData" * (1024 * 8 + 1)
9091

9192
# Reduce socket buffer size to test on relative small data sets.
9293
BUF_SIZE = 4 * 1024 # 4 KiB
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix asyncio sendfile support when sendfile sends extra data in fallback
2+
mode.

0 commit comments

Comments
 (0)