Skip to content

gh-152099: Raise SendfileNotAvailableError for fallback-only transports#152223

Open
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:investigate/asyncio-sendfile-exceptions
Open

gh-152099: Raise SendfileNotAvailableError for fallback-only transports#152223
zainnadeem786 wants to merge 1 commit into
python:mainfrom
zainnadeem786:investigate/asyncio-sendfile-exceptions

Conversation

@zainnadeem786

Copy link
Copy Markdown
Contributor

Summary

This PR makes BaseEventLoop.sendfile() consistently raise asyncio.SendfileNotAvailableError when native sendfile cannot be used for fallback-capable transports (such as SSL/TLS) and fallback=False.

Currently, native sendfile failures on _SendfileMode.TRY_NATIVE transports already raise SendfileNotAvailableError, while _SendfileMode.FALLBACK transports raise a generic RuntimeError. This results in inconsistent exception behavior for the same practical condition: native sendfile is unavailable and fallback has been disabled.

The change updates only the fallback-only transport path. Unsupported transports and closing transports continue to raise RuntimeError unchanged.

Changes

  • Raise SendfileNotAvailableError instead of RuntimeError for _SendfileMode.FALLBACK when fallback=False.
  • Update the corresponding asyncio sendfile test to expect the public exception type.
  • Keep all other code paths unchanged.

Validation

Executed:

PCbuild\amd64\python_d.exe -m test test_asyncio -m test_sendfile_no_fallback_for_fallback_transport
PCbuild\amd64\python_d.exe -m test test_asyncio.test_sendfile
git diff --check

All focused tests passed.

Compatibility

SendfileNotAvailableError subclasses RuntimeError, so existing code catching RuntimeError continues to work while allowing applications to reliably detect native sendfile unavailability.

Closes gh-152099.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.loop.sendfile(fallback=False) raises inconsistent exceptions when native sendfile is unavailable

1 participant