Support conditional sendfile based on transport and platform#214
Conversation
Add use_sendfile flag to read state to conditionally use file:sendfile() for TCP on non-macOS systems, while falling back to pread+send for SSL and macOS. Update tests to be platform-aware using assert_sendfile_pread.
There was a problem hiding this comment.
Pull request overview
Adds transport/platform-aware selection of file:sendfile/5 vs file:pread/3 + socket send when streaming chunks, and updates tests to tolerate macOS behavior differences.
Changes:
- Extend the reader state with a
use_sendfileflag derived from transport and OS type. - Route
send_file/3through a newsendfile/6implementation that can fall back topread+send. - Make sendfile-related tests macOS-aware via
assert_sendfile_pread/3.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/osiris_log.erl |
Introduces use_sendfile in read state and threads it into send_file/3 to disable sendfile on SSL/macOS. |
test/osiris_log_SUITE.erl |
Updates sendfile expectations to account for macOS using pread instead of sendfile. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
michaelklishin
left a comment
There was a problem hiding this comment.
I confirm that this change eliminates a macOS-specific osiris_replica:parse_chunk/3 function_clause when a replica stops (e.g. in RabbitMQ tests).
The root cause comes down to a write(2) followed by sendfile(2) not guaranteed data delivery order even in the case of TCP sockets, which trips up the above function. Or at least that's our best current understanding.
Add use_sendfile flag to read state to conditionally use file:sendfile() for TCP on non-macOS systems, while falling back to pread+send for SSL and macOS. Update tests to be platform-aware using assert_sendfile_pread.