Xuanwo opened a new pull request, #8934: URL: https://github.com/apache/opendal/pull/8934
# Which issue does this PR close? No linked issue. # Rationale for this change Two write error-handling bugs in `opendal-core`: 1. `Operator::write_inner` dropped its internal `Writer` without calling `abort()` when `write()` or `close()` failed. Because callers of `Operator::write` / `write_with` / `write_options` never hold the `Writer` handle, failed multi-chunk writes or failed conditional `close()` calls could leak uncommitted multipart uploads, staged blocks, or temporary files. 2. `WriteState::copy_from` installed `pending_copy` before calling `drive_copy()` and never cleared it when 0 bytes were accepted before an error or future cancellation. This permanently rejected subsequent `write()`, `copy_from()`, and `close()` calls on a healthy `Writer`, even though `Writer::copy_from` only requires resuming or aborting after bytes have been partially accepted. # What changes are included in this PR? - In `Operator::write_inner`, call `let _ = w.abort().await;` when either `w.write(bs).await` or `w.close().await` returns an error, matching `Operator::copy_inner` and preserving the original error. - Track the starting offset (`start`) in `PendingCopy` and treat a pending copy as partially accepted only when `offset > start`. Clear any unaccepted `pending_copy` when `drive_copy()` returns an error and at the entry of `WriteState::check_writable` and `WriteState::copy_from` so a failed or cancelled 0-byte copy does not poison the writer, while preserving the resume-or-abort requirement once at least one byte has been accepted. - Add unit tests in `types::operator` verifying `write_options` invokes `abort()` once and preserves the original error on chunk write failure and `close()` failure (including when `abort()` itself fails). - Add unit tests in `types::context::write` covering 0-byte `copy_from` failures (`NotFound`, `ConditionNotMatch`), 0-byte cancellation followed by `write()`, `copy_from()`, or `close()`, and enforcement of resume-or-abort after a partial copy. # Are there any user-facing changes? Yes. Failed `Operator::write*` calls now abort the underlying writer before returning the original error, and `Writer::copy_from*` calls that fail or are cancelled before accepting any bytes leave the `Writer` usable for subsequent operations. # Breaking changes # AI Usage Statement - Harness: Pi (T3 Code) - Model: Gemini 4 Neon - Effort: high - Role: Implemented both fixes and unit tests and verified them against `opendal-core` tests, clippy, rustfmt, doctests, and rustdoc. No known unknowns affecting review. -- 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]
