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

   # Which issue does this PR close?
   
   N/A. This fixes a verified panic reproduced by the focused unit tests in 
this PR.
   
   # Rationale for this change
   
   `BufferStream::metadata` replaced `self.state` with `State::Idle(None)` 
before awaiting read preparation. If the returned future was dropped while 
pending, for example by `tokio::select!` or `tokio::time::timeout`, the stream 
permanently lost its reader. A later `Stream::poll_next` panicked on 
`reader.take().unwrap()`, and a later `metadata()` panicked on 
`reader.expect(...)`.
   
   A direct `&mut` await is not enough to make this cancel-safe: 
`ReadGenerator::next_reader` advances the generator range before awaiting 
`open`, and `ChunkedReader::prepare_metadata` advances its own range the same 
way. Dropping the future at the open await would lose that range even if the 
reader stayed in the state.
   
   # What changes are included in this PR?
   
   - `BufferStream` now stores an in-flight metadata preparation future in 
`State::PreparingMetadata`. The future owns the reader, so dropping 
`metadata()` preserves both the reader and the progress it already made. A 
later `metadata()` resumes the same future; `poll_next` also drives it to 
completion before reading.
   - `metadata()` called while a read is in flight still returns 
`ErrorKind::Unsupported` without awaiting, which is already cancel-safe. No 
completed read buffer needs to be retained.
   - Added focused tests that poll `metadata()` to `Pending` before an `open` 
completes, drop it, and verify that both `metadata()` and `next()` continue to 
work. Another test covers `metadata()` while `next()` is pending and then 
resumes the stream.
   - Documented that dropping the metadata future does not lose the stream 
reader.
   
   # Are there any user-facing changes?
   
   Canceled metadata calls no longer poison the stream. There are no API or 
successful-path behavior changes.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi coding agent
   - Model: group/deepseek
   - Effort: max
   - Role: Implemented the state-machine fix and focused tests, and ran the 
targeted unit tests, read behavior tests against memory, clippy, and rustfmt 
checks. The human author remains accountable for the change.
   


-- 
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