Skip to content

Unable to cancel S3Client.putObject(input:) #1977

@samwyndham

Description

@samwyndham

Describe the bug

When uploading a file using S3Client.putObject(input:) task cancellation does not cause the underlying request to cancel as it does with an ordinary URLSessionTask.

Furthermore there doesn't appear to be any other mechanism to cancel this upload.

Expected Behavior

If S3Client.putObject(input:) is called within an asynchronous Task and that task is cancelled, the upload should also be cancelled.

Current Behavior

If S3Client.putObject(input:) is called within an asynchronous Task and that task is cancelled, the upload completes.

Reproduction Steps

Running the following code:

let input: PutObjectInput = // ... some valid object

let task = Task {
    do {
        print("\(Date.now): upload will start")
        let response = try await s3.putObject(input: input)
        print("\(Date.now): upload complete")
    } catch {
        print("\(Date.now): upload cancelled")
    }
}

try await Task.sleep(for: .seconds(1))
print("\(Date.now): will cancel task")
task.cancel()
print("\(Date.now): did cancel task")

print("\(Date.now): waiting")
try await Task.sleep(for: .seconds(60))

Prints:

2025-07-03 15:37:44 +0000: upload will start
2025-07-03 15:37:45 +0000: will cancel task
2025-07-03 15:37:45 +0000: did cancel task
2025-07-03 15:37:45 +0000: waiting
2025-07-03 15:37:54 +0000: upload complete

Possible Solution

No response

Additional Information/Context

Note, I asked about cancellation in this discussion but now think this is a bug.

AWS SWIFT SDK version used

1.3.43

Compiler and Version used

Xcode 16.3

Operating System and version

iOS 18.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions