Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel S3 requests when dropped #794

Merged
merged 4 commits into from
Mar 6, 2024

Conversation

jamesbornholt
Copy link
Member

Description of change

Today we don't cancel S3 requests when dropped. For our prefetcher that
means we keep streaming (up to) 2GB of data that will never be used.
This change cancels in-flight requests when dropped, so that the CRT
will stop streaming them. Some bytes might still be in flight or
delivered, which is fine. Canceling requests is a no-op if they've
already completed.

The tricky case for this change is PutObject. Our current implementation
of PutObjectRequest::write blocks until the bytes it provides are
consumed by the client. But sometimes the client might stop reading from
the stream because the request has failed. That case happens to work
today because we don't retain a reference to the meta request ourselves,
and so the failed request's destructors run immediately after the
failure, which unblocks the writer and returns it an error. But now we do
hold onto a reference, and the destructors can't run until the last
reference is released, so the writer is never unblocked. To fix this, we
make the write and complete methods of the PutObjectRequest poll
both the write stream and the request itself in parallel. If the request
completes, this gives us a chance to bail out of the write rather than
blocking forever.

Relevant issues: fixes #510.

Does this change impact existing behavior?

No.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and I agree to the terms of the Developer Certificate of Origin (DCO).

Today we don't cancel S3 requests when dropped. For our prefetcher that
means we keep streaming (up to) 2GB of data that will never be used.
This change cancels in-flight requests when dropped, so that the CRT
will stop streaming them. Some bytes might still be in flight or
delivered, which is fine. Canceling requests is a no-op if they've
already completed.

The tricky case for this change is PutObject. Our current implementation
of `PutObjectRequest::write` blocks until the bytes it provides are
consumed by the client. But sometimes the client might stop reading from
the stream because the request has failed. That case happens to work
today because we don't retain a reference to the meta request ourselves,
and so the failed request's destructors run immediately after the
failure, which unblocks the writer and returns it an error. But now we do
hold onto a reference, and the destructors can't run until the last
reference is released, so the writer is never unblocked. To fix this, we
make the `write` and `complete` methods of the `PutObjectRequest` poll
_both_ the write stream and the request itself in parallel. If the request
completes, this gives us a chance to bail out of the write rather than
blocking forever.

Signed-off-by: James Bornholt <[email protected]>
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt had a problem deploying to PR integration tests March 4, 2024 02:04 — with GitHub Actions Failure
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 4, 2024 02:04 — with GitHub Actions Inactive
mountpoint-s3-client/tests/get_object.rs Show resolved Hide resolved
@@ -167,9 +169,51 @@ async fn test_put_object_abort() {

drop(request); // Drop without calling complete().

// Allow for the AbortMultipartUpload to complete.
// Try to wait a while for the async abort to complete. For the larger object, this might be
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still messing with it to confirm, but it looks like a CRT-side issue — the AbortMultipartUpload can race with in-flight UploadParts, which might succeed after the Abort succeeds and so re-create the upload. I'm not sure if that's worth fixing here (since we're not actually changing how PUT works), so I might just disable the test for large objects.

@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt had a problem deploying to PR integration tests March 5, 2024 03:36 — with GitHub Actions Failure
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 03:36 — with GitHub Actions Inactive
The CRT abort is best-effort -- part uploads can succeed after the Abort
succeeds, which effectively recreates the MPU. This is mentioned in the
AbortMultipartUpload documentation.

Signed-off-by: James Bornholt <[email protected]>
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:24 — with GitHub Actions Inactive
Signed-off-by: James Bornholt <[email protected]>
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt temporarily deployed to PR integration tests March 5, 2024 22:56 — with GitHub Actions Inactive
@jamesbornholt jamesbornholt requested a review from passaro March 5, 2024 23:22
Copy link
Contributor

@passaro passaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@monthonk monthonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I was planning to put a PR up for this but the trick with PutObjectRequest is what I was still figuring out.

@jamesbornholt jamesbornholt marked this pull request as ready for review March 6, 2024 16:33
@jamesbornholt jamesbornholt added this pull request to the merge queue Mar 6, 2024
Merged via the queue into awslabs:main with commit ab39c1d Mar 6, 2024
25 checks passed
@jamesbornholt jamesbornholt deleted the clean-up-requests branch March 6, 2024 16:51
passaro added a commit to passaro/mountpoint-s3 that referenced this pull request Nov 22, 2024
The issue was addressed in Cancel S3 requests when dropped [awslabs#794](awslabs#794).

Signed-off-by: Alessandro Passaro <[email protected]>
passaro added a commit to passaro/mountpoint-s3 that referenced this pull request Nov 25, 2024
The issue was addressed in Cancel S3 requests when dropped [awslabs#794](awslabs#794).

Signed-off-by: Alessandro Passaro <[email protected]>
@passaro passaro mentioned this pull request Nov 25, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 25, 2024
The issue has already been addressed in Cancel S3 requests when dropped
[#794](#794).

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and I agree to the terms of
the [Developer Certificate of Origin
(DCO)](https://developercertificate.org/).

Signed-off-by: Alessandro Passaro <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dropped GetObject requests are not cancelled in CRT bindings
3 participants