hcrosse opened a new issue, #8584: URL: https://github.com/apache/opendal/issues/8584
### OpenDAL version `v0.59.5` (`main`) ### Affected service or component `services/s3` with `RetryLayer` and `TimeoutLayer` ### Describe the bug When an S3 mutation or multipart completion commits on attempt 1 and the response is lost due to TCP EOF, TCP reset, `TimeoutLayer` cancellation, or a gateway 5xx, `RetryLayer` replays the same request. Because S3 has no idempotency token header for these requests, the replay hits a state failure caused by the committed first attempt and OpenDAL reports a false authoritative error: 1. Conditional mutations (`if_not_exists`, `if_match`, `delete_with().if_match()`, conditional copy, and conditional append at offset 0) replay in [`S3Writer::write_once`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/writer.rs#L78-L106), [`S3Copier::copy_once`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/copier.rs#L174-L247), and [`S3Deleter::delete_once`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/deleter.rs#L42-L66). Attempt 2 receives `412 PreconditionFailed` or `404 NoSuchKey` on conditional delete, so OpenDAL returns `ErrorKind::ConditionNotMatch` even though attempt 1 committed. Under the [conditional operations specification](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/core/src/docs/specs/conditional-operations.md#L110-L121), `ConditionNotMatch` tells callers their condition evaluated to false, which leads them to discard or roll back the attempt instead of checking storage. 2. Multipart completion in [`S3Writer::complete_part`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/writer.rs#L245-L325) and [`S3Copier::complete_copy`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/copier.rs#L337-L410) replays `CompleteMultipartUpload` with the same `uploadId` after a lost commit response and receives `404 NoSuchUpload`, surfacing `ErrorKind::NotFound` even though the object committed (related to #5101). 3. [`parse_s3_error_code`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/core.rs#L2267-L2324) also has two gaps against [RFC 8145](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/core/src/docs/rfcs/8145_conflict_error_kind.md#L122-L155): - `OperationAborted` is still marked temporary on `CompleteMultipartUpload` at [`parse_s3_error_code`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/core.rs#L2287), unlike `ConditionalRequestConflict` at [`parse_s3_error_code`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/core.rs#L2318-L2321). - `NoSuchUpload` has no explicit mapping and falls back to HTTP 404 `ErrorKind::NotFound`. With `if_match`, [`S3Writer::complete_part`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/writer.rs#L296-L323) and [`S3Copier::complete_copy`](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/services/s3/src/copier.rs#L373-L408) rewrite any `NotFound` into `ErrorKind::ConditionNotMatch`, turning a missing upload session into a missing target key error. ### Steps to Reproduce 1. Configure an S3 `Operator` with `RetryLayer`. 2. Run `op.write_with("k", data).if_not_exists(true).await`, `op.write_with("k", data).if_match(etag).await`, `op.delete_with("k").if_match(etag).await`, or a multipart `writer.close().await`. 3. Have the S3 endpoint commit attempt 1 and close the connection with EOF or RST, return a 5xx after commit, or hit `TimeoutLayer` inside `RetryLayer`. 4. Observe attempt 2 replayed by `RetryLayer`. ### Actual Behavior - Conditional write, copy, and delete return `ErrorKind::ConditionNotMatch` even though attempt 1 committed. - Unconditional `CompleteMultipartUpload` returns `ErrorKind::NotFound` on `404 NoSuchUpload`, and conditional `CompleteMultipartUpload` with `if_match` turns `404 NoSuchUpload` into `ErrorKind::ConditionNotMatch`. - `OperationAborted` on `CompleteMultipartUpload` is treated as temporary and retried. ### Expected Behavior - `OperationAborted` on `CompleteMultipartUpload` returns permanent `ErrorKind::Conflict` and is not retried. - `NoSuchUpload` on `CompleteMultipartUpload` returns permanent `ErrorKind::Unexpected` rather than `ErrorKind::NotFound` or `ErrorKind::ConditionNotMatch` under `if_match`. - After an ambiguous attempt (transport error, `TimeoutLayer` cancellation, or 5xx response), a retry that receives `412`, `NoSuchKey` under `if_match`, or `NoSuchUpload` returns permanent `ErrorKind::Unexpected` so callers know the outcome is uncertain and reconcile storage, instead of receiving a false `ConditionNotMatch` or `NotFound`. - If attempt 1 failed before committing (for example DNS or connect failure, credential refresh, `429`/`SlowDown`, or an AWS `200` XML error on `CompleteMultipartUpload`), the retry still succeeds. ### Proposed Approach To keep `RetryLayer` driven solely by `Error::is_temporary()` per [RFC 8145](https://github.com/apache/opendal/blob/e60a63f6add87c13bce20e24675f03cdfcba1b6d/core/core/src/docs/rfcs/8145_conflict_error_kind.md#L77-L78), preserve GCS recovery in #8199 and #8517, and catch `TimeoutLayer` cancellations inside `RetryLayer`, `S3Writer`, `S3Copier`, and `S3Deleter` can set an uncertain dispatch flag after signing and clear it on any definite response (`200`, `429`/`SlowDown`, `408`, `409`, or first attempt `412`/`404`). I am opening a first PR for the `OperationAborted` and `NoSuchUpload` fixes in `parse_s3_error_code`. Before sending follow up PRs for `CompleteMultipartUpload` and conditional mutations, does that permanent `ErrorKind::Unexpected` replay contract look right for `services/s3`? -- 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]
