Xuanwo opened a new pull request, #8748: URL: https://github.com/apache/opendal/pull/8748
# Which issue does this PR close? No issue: these bugs were found while auditing the `Copier` state machine. # Rationale for this change Driving `Copier` as a `Stream` never completed the copy. `poll_next` returned `None` as soon as `next_dyn` finished and never called `close_dyn`, so callers that consumed the copier as a stream, such as `copier.try_collect::<Vec<_>>().await?`, observed completion while server-side completion and size validation in `close_dyn` had not run. Re-polling such a stream called `next_dyn` again instead of ending the stream. The same state handling made cancellation unsafe. A `poll_next` that returned `Poll::Pending` moved the inner copier into the in-flight future, so a later `abort` returned `Ok(())` without aborting, and a later `close` returned `Ok(Metadata::unknown())` without finishing the copy. `abort` also left the copier usable afterwards, and a failing `close_dyn` in `next` did not mark the copier as failed. # What changes are included in this PR? `Copier` now tracks an explicit state (idle, in flight, closed, aborted, failed) instead of deriving it from the presence of the inner copier: - A stream poll advances the copy and, once `next_dyn` finishes, closes the inner copier in the same step. The metadata from `close_dyn` is kept for `close`, and a failed `close_dyn` is surfaced as the stream item and marks the copier failed, so later polls and `next` calls return `None` without touching the inner copier. - The step future stays in the copier while it is awaited. `next`, `close`, and `abort` await that future in place, so canceling a stream poll or a `next`/`close`/`abort` call keeps the step resumable instead of losing the inner copier. As a result, `abort` really calls `abort_dyn`, and `close` drives the copy to completion and calls `close_dyn`. - `abort` makes the copier terminal: after a successful abort, `next` and stream polls return `None` and `close` fails. A failing `abort_dyn` keeps the inner copier so a retried abort can clean up the same server-side copy. - `close` after `abort` fails instead of returning unknown metadata, and `close` after a failure still reports the failure. Public signatures are unchanged. # Are there any user-facing changes? `Copier` behavior changes, all fixing silent wrong results: - Consuming a `Copier` as a stream now finalizes the copy before the stream ends, so `close_dyn` failures surface as stream errors instead of `None`. - `Copier::abort` after a completed copy is a no-op, and after a successful abort `Copier::close` returns an error rather than unknown metadata. # Breaking changes # AI Usage Statement - Harness: pi coding agent - Model: group/deepseek - Effort: max - Role: Analyzed the `Copier` state machine, wrote the implementation and unit tests, and ran the focused unit, behavior, clippy, fmt, wasm, and rustdoc checks. The `Copier` behavior tests were run against the `fs` service because the `memory` service does not report the `copy` capability and therefore skips them. -- 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]
