From: Zain Nadeem Date: Sun, 28 Jun 2026 10:26:27 +0000 (+0500) Subject: gh-152099: Raise SendfileNotAvailableError for fallback-only transports in asyncio... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a385d204d0ec720f044cbfbbad0e4e7360f93392;p=thirdparty%2FPython%2Fcpython.git gh-152099: Raise SendfileNotAvailableError for fallback-only transports in asyncio (#152223) --- diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index bb736222b0b3..93bd7df993d8 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -1283,7 +1283,7 @@ class BaseEventLoop(events.AbstractEventLoop): raise if not fallback: - raise RuntimeError( + raise exceptions.SendfileNotAvailableError( f"fallback is disabled and native sendfile is not " f"supported for transport {transport!r}") return await self._sendfile_fallback(transport, file, diff --git a/Lib/test/test_asyncio/test_sendfile.py b/Lib/test/test_asyncio/test_sendfile.py index 2d5c06f82b3d..69ac9a367f6b 100644 --- a/Lib/test/test_asyncio/test_sendfile.py +++ b/Lib/test/test_asyncio/test_sendfile.py @@ -580,7 +580,8 @@ class SendfileMixin(SendfileBase): transport = mock.Mock() transport.is_closing.side_effect = lambda: False transport._sendfile_compatible = constants._SendfileMode.FALLBACK - with self.assertRaisesRegex(RuntimeError, 'fallback is disabled'): + with self.assertRaisesRegex(asyncio.SendfileNotAvailableError, + 'fallback is disabled'): self.loop.run_until_complete( self.loop.sendfile(transport, None, fallback=False)) diff --git a/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst b/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst new file mode 100644 index 000000000000..05e760bcf6ed --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst @@ -0,0 +1,4 @@ +``asyncio``'s ``loop.sendfile(..., fallback=False)`` now consistently raises +:exc:`asyncio.SendfileNotAvailableError` for fallback-only transports, such as +SSL/TLS transports, when native sendfile cannot be used. Previously, this case +raised :exc:`RuntimeError`.