diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index 546361f80b1f47..ff63639638c13f 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1295,8 +1295,8 @@ async def _sendfile_fallback(self, transp, file, offset, count): read = await self.run_in_executor(None, file.readinto, view) if not read: return total_sent # EOF - await proto.drain() transp.write(view[:read]) + await proto.drain() total_sent += read finally: if total_sent > 0 and hasattr(file, 'seek'): diff --git a/Misc/NEWS.d/next/Library/2025-03-17-18-50-39.gh-issue-131325.wlasMF.rst b/Misc/NEWS.d/next/Library/2025-03-17-18-50-39.gh-issue-131325.wlasMF.rst new file mode 100644 index 00000000000000..6c1f64eee6ad02 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-17-18-50-39.gh-issue-131325.wlasMF.rst @@ -0,0 +1 @@ +Fix sendfile fallback implementation to drain data after writing to transport in :mod:`asyncio`.