Xuanwo opened a new pull request, #8928:
URL: https://github.com/apache/opendal/pull/8928

   # Which issue does this PR close?
   
   N/A.
   
   # Rationale for this change
   
   `BufferStream::poll_next` can enter an infinite error loop (spinning at 100% 
CPU and causing unbounded allocation when collected via `Stream::collect`, 
`blocking::BufferIterator::collect`, or `StdBytesIterator::collect`) in two 
unrecoverable paths:
   
   1. **Bounded EOF length mismatch:** When an exact bounded read hits EOF with 
`read != size` (for example, a truncated response or an object that shrank 
during reading), `BufferStream::poll_next` returns the `check_complete` error 
while leaving the stream in `State::Idle(Some(reader))`. Subsequent polls 
immediately observe EOF again with zero I/O and yield `Some(Err(...))` 
indefinitely.
   2. **Concurrent chunked reader permanent error:** When `ChunkedReader` runs 
with `concurrent > 1` and encounters a non-temporary error (such as `NotFound` 
or `PermissionDenied`), `ConcurrentTasks` cancels in-flight tasks and sets 
`errored = true`. Subsequent polls invoke `ChunkedReader::read`, which returns 
`Some(Err("concurrent tasks met an unrecoverable error"))` indefinitely instead 
of terminating the stream.
   
   # What changes are included in this PR?
   
   - Add a `pub(crate)` `ConcurrentTasks::is_errored` accessor and expose it to 
`BufferStream` through `ChunkedReader::is_errored`.
   - Add `State::Done` to `BufferStream` and transition to it when:
     - the stream reaches EOF (whether `check_complete` succeeds or returns a 
length mismatch error),
     - the configured read limit reaches zero, or
     - `ChunkedReader` returns an error after `ConcurrentTasks` enters its 
unrecoverable `errored` state.
   - Preserve retry behavior for recoverable errors (including temporary 
open/chunk errors and recoverable `StreamingReader` read errors).
   - Add unit tests covering both truncated bounded reads and permanent errors 
in concurrent chunked reads, verifying that `next()` yields `Some(Err(...))` 
followed by `None` and that `collect::<Vec<_>>()` terminates.
   
   # Are there any user-facing changes?
   
   `BufferStream` (and wrappers such as `FuturesBytesStream`, 
`blocking::BufferIterator`, and `blocking::StdBytesIterator`) now terminates 
with `None` after yielding an EOF length-mismatch error or an unrecoverable 
concurrent chunk error, instead of looping forever.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Investigated `BufferStream`, `ChunkedReader`, and `ConcurrentTasks` 
error paths; added regression unit tests reproducing both infinite error loops; 
implemented the `State::Done` termination fix; and verified formatting, clippy, 
unit tests, doc tests, and rustdoc.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to