Skip to content

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

Merged
kumaraditya303 merged 1 commit into
python:mainfrom
zainnadeem786:investigate/asyncio-sendfile-exceptions
Jun 28, 2026
Merged

kumaraditya303 merged 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.

Comment thread Lib/test/test_asyncio/test_sendfile.py Resolved
@zainnadeem786
zainnadeem786 force-pushed the investigate/asyncio-sendfile-exceptions branch from 9798125 to 136b1b5 Compare June 27, 2026 09:13
@zainnadeem786
zainnadeem786 requested a review from picnixz June 27, 2026 09:15

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let asyncio's maintainers review that as they have better insight

@kumaraditya303
kumaraditya303 merged commit a385d20 into python:main Jun 28, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants