Skip to content

Commit a385d20

Browse files
gh-152099: Raise SendfileNotAvailableError for fallback-only transports in asyncio (#152223)
1 parent e3ba57b commit a385d20

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/asyncio/base_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ async def sendfile(self, transport, file, offset=0, count=None,
12831283
raise
12841284

12851285
if not fallback:
1286-
raise RuntimeError(
1286+
raise exceptions.SendfileNotAvailableError(
12871287
f"fallback is disabled and native sendfile is not "
12881288
f"supported for transport {transport!r}")
12891289
return await self._sendfile_fallback(transport, file,

Lib/test/test_asyncio/test_sendfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ def test_sendfile_no_fallback_for_fallback_transport(self):
580580
transport = mock.Mock()
581581
transport.is_closing.side_effect = lambda: False
582582
transport._sendfile_compatible = constants._SendfileMode.FALLBACK
583-
with self.assertRaisesRegex(RuntimeError, 'fallback is disabled'):
583+
with self.assertRaisesRegex(asyncio.SendfileNotAvailableError,
584+
'fallback is disabled'):
584585
self.loop.run_until_complete(
585586
self.loop.sendfile(transport, None, fallback=False))
586587

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``asyncio``'s ``loop.sendfile(..., fallback=False)`` now consistently raises
2+
:exc:`asyncio.SendfileNotAvailableError` for fallback-only transports, such as
3+
SSL/TLS transports, when native sendfile cannot be used. Previously, this case
4+
raised :exc:`RuntimeError`.

0 commit comments

Comments
 (0)