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

   # Which issue does this PR close?
   
   N/A.
   
   # Rationale for this change
   
   When a copy step fails, the async `Copier` transitions to 
`State::Failed(inner)` so the underlying `oio::Copier` stays alive until the 
caller calls `abort()` to clean up uncommitted server-side state, while 
subsequent `next()` calls return `Ok(None)`.
   
   `blocking::Copier::next` previously cleared `self.copier = None` upon 
receiving `Ok(None)`. That caused two bugs:
   
   1. If a caller drove a failed `blocking::Copier` to `None` before calling 
`abort()`, `self.copier` had already been dropped, so 
`blocking::Copier::abort()` hit the `None` branch and returned `Ok(())` without 
invoking `oio::Copier::abort()`.
   2. Dropping `self.copier` inside `Iterator::next` ran `AsyncCopier`'s 
destructor directly on the caller's synchronous thread, bypassing 
`blocking::Copier::drop`'s `self.handle.block_on(async move { drop(v) })` guard.
   
   Other blocking iterators (`blocking::Lister`, `blocking::BufferIterator`, 
and `blocking::StdBytesIterator`) do not clear their inner async handle on 
`Ok(None)` and instead rely on `Drop` to tear it down inside `Handle::block_on`.
   
   # What changes are included in this PR?
   
   - Stop clearing `self.copier` in `blocking::Copier::next` when 
`AsyncCopier::next()` returns `Ok(None)`. Repeated `next()` calls continue 
returning `None` via `AsyncCopier`'s state machine, `blocking::Copier::abort()` 
still reaches `oio::Copier::abort()` inside `Handle::block_on`, and 
`blocking::Copier::drop()` drops the remaining `AsyncCopier` inside 
`Handle::block_on`.
   - Add unit tests in `core/core/src/blocking/copy.rs` covering `abort()` 
after a failed iteration reaches `None`, repeated `next()` and `abort()` calls, 
and dropping `blocking::Copier` inside the Tokio runtime context after EOF.
   
   # Are there any user-facing changes?
   
   Yes, this fixes a bug without changing public signatures:
   
   - Calling `blocking::Copier::abort()` after a failed iteration has been 
drained to `None` now aborts the underlying copy operation instead of silently 
succeeding as a no-op.
   - Dropping a `blocking::Copier` after reaching `None` now drops the inner 
async copier inside the Tokio runtime context rather than on the caller's 
synchronous thread.
   
   # Breaking changes
   
   # AI Usage Statement
   
   - Harness: pi
   - Model: Gemini 4 Neon
   - Effort: high
   - Role: Reproduced the bug with unit tests in 
`core/core/src/blocking/copy.rs`, verified they failed before the fix, 
implemented the fix, checked other blocking iterators for consistency, and 
verified formatting, lint, tests, and docs.
   


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