]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152099: Raise SendfileNotAvailableError for fallback-only transports in asyncio...
authorZain Nadeem <zainnadeemzainnadeem80@gmail.com>
Sun, 28 Jun 2026 10:26:27 +0000 (15:26 +0500)
committerGitHub <noreply@github.com>
Sun, 28 Jun 2026 10:26:27 +0000 (15:56 +0530)
Lib/asyncio/base_events.py
Lib/test/test_asyncio/test_sendfile.py
Misc/NEWS.d/next/Library/2026-06-25-22-19-04.gh-issue-152099.L7fKq9.rst [new file with mode: 0644]

index bb736222b0b386617bf308fa05924892d8bb354e..93bd7df993d8270aef2d812776a3ac451ff42edf 100644 (file)
@@ -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,
index 2d5c06f82b3ddf19e7b74ae11d4ca5f5655367c8..69ac9a367f6be02d70bd6e05bdb909e337cf774e 100644 (file)
@@ -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 (file)
index 0000000..05e760b
--- /dev/null
@@ -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`.