Skip to content

meta request: support for should_continue cancellation callback #238

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

Conversation

grrtrr
Copy link
Contributor

@grrtrr grrtrr commented Dec 6, 2022

Add a boolean continue_callback, which polls a request-cancellation flag set by the user. This matches the use-case of the ContinueRequestHandler / ContinueRequest / ShouldContinue boolean functions used by aws-sdk-cpp.

Passive polling is preferred over active cancellation, since the latter would require to store a reference to the s3 meta request. The polling function is evaluated at the following points during the lifetime of the meta request:

  1. Request preparation (aws_s3_meta_request_prepare_request).
  2. Request update (the .update handler invoked via aws_s3_meta_request_update).
  3. Http stream completion (.on_complete handler invoking aws_s3_meta_request_send_request_finish_default).
  4. Writing download data (aws_s3_meta_request_stream_response_body_synced).

If a continue_callback is provided and if it returns false at any of these 4 evaluation times, the meta request completes with the error_code AWS_ERROR_S3_CANCELED.

By using a boolean flag in the body of the function, the polling overhead can be kept minimal.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

grrtrr and others added 2 commits December 6, 2022 09:39
Add a boolean `continue_callback`, which polls a request-cancellation flag set by the user.
This matches the use-case of the `ContinueRequestHandler` / `ContinueRequest` / `ShouldContinue` boolean
functions used by `aws-sdk-cpp`.

Passive polling is preferred over active cancellation, since the latter would require to store a reference
to the s3 meta request. The polling function is evaluated at the following points during the lifetime of the
meta request:
1. _Request preparation_ (`aws_s3_meta_request_prepare_request`).
2. _Request update_ (the `.update` handler invoked via `aws_s3_meta_request_update`).
3. _Http stream completion_ (`.on_complete` handler invoking `aws_s3_meta_request_send_request_finish_default`).
4. _Writing download data_ (`aws_s3_meta_request_stream_response_body_synced`).

If a `continue_callback` is provided and if it returns `false` at any of these 4 evaluation times, the
meta request completes with the `error_code` `AWS_ERROR_S3_CANCELED`.
@codecov-commenter
Copy link

Codecov Report

Merging #238 (01f878e) into main (c95ad5c) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #238      +/-   ##
==========================================
+ Coverage   87.01%   87.05%   +0.04%     
==========================================
  Files          16       16              
  Lines        4036     4041       +5     
==========================================
+ Hits         3512     3518       +6     
+ Misses        524      523       -1     
Impacted Files Coverage Δ
source/s3_meta_request.c 92.82% <100.00%> (+0.04%) ⬆️
source/s3_client.c 86.66% <0.00%> (+0.01%) ⬆️
source/s3_auto_ranged_put.c 91.94% <0.00%> (+0.19%) ⬆️

@jmklix jmklix closed this May 20, 2024
@grrtrr
Copy link
Contributor Author

grrtrr commented May 20, 2024

Hi @jmklix why was this closed without comments. Is there an alternative that can be used and where is it documented?

As it stands, S3Crt requests can not be canceled at the moment.

@TingDaoK
Copy link
Contributor

with #395, we now cancel all the in-flight requests. It's over-complicate the behavior for user to control for each requests. Unless you have a strong opinion with use case, I don't see a point to keep the requests in-flight when you decided to cancel the meta request.

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.

5 participants