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 CRT requests if should not continue #3231

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

SergeyRyabinin
Copy link
Contributor

@SergeyRyabinin SergeyRyabinin commented Dec 23, 2024

Issue #, if available:
awslabs/aws-c-s3#467
S3 CRT integration does not map ShouldContinue callback call
Description of changes:
Add calling the ShouldContinue callback
To be honest, that is not the best solution possible to add the functionality of cancel.
We are going to introduce a better API with the refactoring of the transfer manager to officially support S3 CRT client.
Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@SergeyRyabinin SergeyRyabinin requested a review from sbera87 January 2, 2025 17:16
putObjectRequest2.SetBucket(m_bucketName);
putObjectRequest2.SetKey(TEST_KEY);
std::atomic<bool> shouldContinueAtomic{true};
putObjectRequest2.SetContinueRequestHandler([&shouldContinueAtomic](const HttpRequest*) { return shouldContinueAtomic.load(); });
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand that the atomic flag once set false will prompt the following code in the callback

userData->s3CrtClient->CancelCrtRequestAsync(meta_request);

If the request is called twice, is there safeguard to protect duplicate cancellation of same request in crt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the CRT developers, CRT is safe on calling the cancellation method on the same task handle twice, or even on an invalid task handle pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

crt is fine with stuff being called twice as long as the handle is still valid and meta req has not been released

{
wrappedData->fn(wrappedData->data);
}
wrappedData->clientShutdownSem->Release();
Copy link
Contributor

Choose a reason for hiding this comment

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

null ptr check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thank you

@@ -13,10 +29,17 @@ static int S3CrtRequestHeadersCallback(struct aws_s3_meta_request *meta_request,
userData->response->AddHeader(StringUtils::FromByteCursor(header.name), StringUtils::FromByteCursor(header.value));
}
userData->response->SetResponseCode(static_cast<HttpResponseCode>(response_status));

auto& shouldContinueFn = userData->originalRequest->GetContinueRequestHandler();
Copy link
Contributor

Choose a reason for hiding this comment

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

though this is not added in this PR, I think we should add ptr null checks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thank you!

{
wrappedData->fn(wrappedData->data);
}
wrappedData->clientShutdownSem->Release();
Copy link
Contributor

Choose a reason for hiding this comment

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

null ptr check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved this method from .h to .cpp, but it is added now, thank you.

Copy link
Contributor

@sbera87 sbera87 left a comment

Choose a reason for hiding this comment

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

Looks good overall. Just need some ptr null checks . Open question about effect of duplicate request cancellation

Copy link
Contributor

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

@DmitriyMusatkin DmitriyMusatkin left a comment

Choose a reason for hiding this comment

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

havent reviewed in depth and will leave cpp/style comments for someone more familiar with cpp, but from crt perspective this looks fine

@SergeyRyabinin SergeyRyabinin merged commit a94edca into main Jan 2, 2025
4 of 5 checks passed
@SergeyRyabinin SergeyRyabinin deleted the sr/cancelS3CrtReq branch January 2, 2025 23:23
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.

4 participants