Xuanwo opened a new issue, #8853:
URL: https://github.com/apache/opendal/issues/8853

   > AI-authored bug report from a source audit against `main` (`615a8f24f`). 
Verified by code inspection of `opendal-core`'s pure-Rust state transitions in 
`MultipartCopier` and `BlockCopier` (no external service dependency).
   
   ### Affected Component
   
   - `core/core/src/raw/oio/copy/multipart_copy.rs` (`MultipartCopier`)
   - `core/core/src/raw/oio/copy/block_copy.rs` (`BlockCopier`)
   - Commit: `615a8f24f`
   
   ### Describe the Bug
   
   Both `MultipartCopier` (`multipart_copy.rs:102-116`) and `BlockCopier` 
(`block_copy.rs:78-91`) overload `completed: bool` + `metadata: 
Option<Metadata>` to represent both "completed" and "aborted", leading to 
broken `abort()` lifecycle behavior:
   
   1. **`close()` after `abort()` fabricates `Ok(Metadata)` in both copiers:**
      - `MultipartCopier::abort()` (`multipart_copy.rs:359-372`) sets 
`self.completed = true; self.metadata = None; self.upload_id = None;` after 
`abort_copy` succeeds.
      - `BlockCopier::abort()` (`block_copy.rs:288-302`) sets `self.completed = 
true; self.metadata = None;`.
      - Calling `close()` afterwards (`multipart_copy.rs:331-357`, 
`block_copy.rs:259-286`) skips `while !self.completed`, falls back to 
`MetadataBuilder::unknown().build()`, applies `builder.set_file(source_size)` 
when `source_size` is known, and returns `Ok(Metadata)` for an aborted copy.
   2. **`MultipartCopier::abort()` before `initiate_copy()` does not mark the 
copier aborted:**
      - When `self.upload_id` is `None` (`multipart_copy.rs:363-365`), 
`abort()` returns `Ok(())` without updating state, so a subsequent `next()` or 
`close()` proceeds to execute the copy.
   3. **`BlockCopier::abort()` sends duplicate `abort_block` calls on repeated 
`abort()`:**
      - `BlockCopier::abort()` (`block_copy.rs:296-301`) never clears 
`self.scheduled_block_ids` after `abort_block` succeeds (unlike `BlockWriter`, 
which was fixed in #8802). Calling `abort()` a second time sends `abort_block` 
again with the same block IDs.
   
   ### Expected Behavior
   
   - Once `abort()` succeeds (whether before or after initiation), the copier 
transitions to an explicit aborted state:
     - Subsequent `abort()` calls are idempotent no-ops (never re-sending 
`abort_copy` or `abort_block`).
     - Subsequent `close()` (and `next()`) calls fail instead of fabricating 
`Ok(Metadata)` or starting a new copy.
   - Replacing `completed: bool` + `metadata: Option<Metadata>` with an 
explicit lifecycle enum (e.g., `Running` / `Completed(Metadata)` / `Aborted`) 
makes all valid transitions explicit in one place.
   
   ### Reproduction
   
   Minimal deterministic unit tests against the existing `TestCopy` / mock 
`BlockCopy` harnesses in `multipart_copy.rs` and `block_copy.rs`:
   1. Advance `MultipartCopier` or `BlockCopier` enough to initiate/schedule a 
part or block, call `abort().await?`, then call `close().await` -> currently 
returns `Ok(Metadata)` instead of `Err`.
   2. Call `MultipartCopier::abort().await?` before `next()`, then call 
`close().await` -> currently executes the copy instead of failing.
   3. Schedule a block in `BlockCopier`, call `abort().await?` twice -> 
currently invokes `BlockCopy::abort_block` twice.
   


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