fix(core): Return Ok(0) instead of panicking on zero-length write - #8162
Merged
Xuanwo merged 1 commit intoAug 26, 2026
Merged
Conversation
`FuturesAsyncWriter::poll_write` panicked with `frozen buffer must be valid` when called with an empty buffer, even though both `std::io::Write::write` and `futures::AsyncWrite::poll_write` allow a zero-length input and specify `Ok(0)` as the result. `FlexBuf::put` returns 0 both when the buffer is already frozen and when the input slice is empty. The loop in `poll_write` assumed only the first case, so on an empty input it called `get()` on a buffer that was never frozen and hit the `expect`. `BufferSink` already guards this case, so add the same guard to the adapter. The blocking `StdWriter` path is fixed transitively, since it forwards to `FuturesAsyncWriter::write`. Closes apache#8161
bavardage
force-pushed
the
fix-futures-async-writer-empty-write
branch
from
August 26, 2026 15:51
1eccbfa to
e424347
Compare
Xuanwo
approved these changes
Aug 26, 2026
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.
FuturesAsyncWriter::poll_writepanicked withfrozen buffer must be validwhen called with an empty buffer, even though bothstd::io::Write::writeandfutures::AsyncWrite::poll_writeallow a zero-length input and specifyOk(0)as the result.FlexBuf::putreturns 0 both when the buffer is already frozen and when the input slice is empty. The loop inpoll_writeassumed only the first case, so on an empty input it calledget()on a buffer that was never frozen and hit theexpect.BufferSinkalready guards this case, so add the same guard to the adapter.The blocking
StdWriterpath is fixed transitively, since it forwards toFuturesAsyncWriter::write.Closes #8161
Which issue does this PR close?
Closes #8161
What changes are included in this PR?
core/core/src/types/write/futures_async_writer.rs: returnPoll::Ready(Ok(0))frompoll_writewhen the input buffer is empty, before entering the drain loop.after a non-empty one, and asserting the surrounding payload still commits and reads back
intact.
Are there any user-facing changes?
Yes but nothing breaking. The zero length previously panicked and now returns
Ok(0). No API signaturechanges, and no behavior change for any non-empty write.
AI Usage Statement
AI identified this bug when using opendal in my project and identified this as a potential fix.
The fix is pretty simple though!