Skip to content

Cancel S3 CRT requests if should not continue - #3231

Merged
SergeyRyabinin merged 1 commit into
mainfrom
sr/cancelS3CrtReq
Jan 2, 2025
Merged

Cancel S3 CRT requests if should not continue#3231
SergeyRyabinin merged 1 commit into
mainfrom
sr/cancelS3CrtReq

Conversation

@SergeyRyabinin

@SergeyRyabinin SergeyRyabinin commented Dec 23, 2024

Copy link
Copy Markdown
Contributor

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

}
userData->response->SetResponseCode(static_cast<HttpResponseCode>(response_status));

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@sbera87 sbera87 left a comment

Copy link
Copy Markdown
Contributor

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

@sbera87 sbera87 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@DmitriyMusatkin DmitriyMusatkin left a comment

Copy link
Copy Markdown
Contributor

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

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