Fix false positive for os.sendfile via asyncio sock_sendfile path - #58
Merged
Merged
Conversation
The os.sendfile whitelist only covered the transport-level loop.sendfile() path through asyncio/base_events.py. The socket-level loop.sock_sendfile() path goes through asyncio/unix_events.py:_sock_sendfile_native_impl, which is what aiohttp's FileResponse ends up on the selector event loop. That syscall runs on a non-blocking socket and handles EAGAIN by registering a writer, so it does not actually block. Fixes cbornet#57
14 tasks
agners
added a commit
to home-assistant/supervisor
that referenced
this pull request
May 20, 2026
Serving aiohttp FileResponse triggers BlockBuster's os.sendfile guard because the actual syscall happens in asyncio/unix_events.py's _sock_sendfile_native_impl rather than the base_events.sendfile entry point that blockbuster whitelists. The socket is non-blocking and EAGAIN is handled by re-registering a writer, so the call is safe. Extend the os.sendfile allowlist with the selector-loop caller as a local workaround. Fixed upstream by cbornet/blockbuster#58 (issue cbornet/blockbuster#57); drop this once blockbuster is bumped to a version that includes the fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
agners
added a commit
to home-assistant/supervisor
that referenced
this pull request
May 22, 2026
Serving aiohttp FileResponse triggers BlockBuster's os.sendfile guard because the actual syscall happens in asyncio/unix_events.py's _sock_sendfile_native_impl rather than the base_events.sendfile entry point that blockbuster whitelists. The socket is non-blocking and EAGAIN is handled by re-registering a writer, so the call is safe. Extend the os.sendfile allowlist with the selector-loop caller as a local workaround. Fixed upstream by cbornet/blockbuster#58 (issue cbornet/blockbuster#57); drop this once blockbuster is bumped to a version that includes the fix. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends the
os.sendfilewhitelist to also allow the selector event loop's socket-level path (asyncio/unix_events.py:_sock_sendfile_native_impl). This is the path aiohttp'sFileResponseends up on when serving static files, so any aiohttp app using blockbuster currently hits a false positiveBlockingError.The whitelisted call site runs
os.sendfileon a non-blocking socket and explicitly handlesBlockingIOError/InterruptedErrorby registering a writer on the fd — i.e. the syscall returnsEAGAINinstead of blocking, just like the already-whitelistedasyncio/base_events.py:sendfilepath.The two whitelist entries cover the two stack shapes that reach
os.sendfile:os.sendfilecall sends everything in one go, the call frame chain includesbase_events.py:sendfiledirectly (covered by the existing entry)add_writercallback and re-enters_sock_sendfile_native_implfrom the event loop's callback dispatch — the stack no longer goes throughbase_events.py:sendfile, so we need the new entryFixes #57
Test plan
test_os_sendfilestill passes (uv run pytest -k sendfile)add_writerpathBlockingErrorin the server logs