Skip to content

feat: support cancellation of synchronous REST requests - #16663

Open
mtibben wants to merge 2 commits into
googleapis:mainfrom
mtibben:mtibben/rest-request-cancellation
Open

mtibben wants to merge 2 commits into
googleapis:mainfrom
mtibben:mtibben/rest-request-cancellation

Conversation

@mtibben

@mtibben mtibben commented Nov 12, 2026

Copy link
Copy Markdown

Synchronous REST requests cannot currently be cancelled while an SDK call is blocked. Checking an application cancellation flag between calls or disabling retries does not interrupt an active request, so an application can remain blocked waiting for the server or a timeout.

Add an experimental RestCancellation handle and RestCancellationOption for per-call options, including storage::Client operations and streams. Another thread can request cancellation, interrupting libcurl waits, preventing further retries, and reporting kCancelled through existing result or stream-error mechanisms. Streams retain cancellation state throughout their lifetime, and cancelled upload cleanup avoids finalizing buffered partial data.

Cancellable requests use bounded polling without accessing libcurl handles from another thread. Cancellable Storage reads bypass hedging so queued workers cannot delay cancellation. Credential acquisition already in progress remains outside this scope, and cancellation does not roll back operations the server has already committed.

@mtibben
mtibben requested review from a team as code owners November 12, 2026 23:08

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces cooperative cancellation support for synchronous REST operations by adding a copyable RestCancellation handle and RestCancellationOption. It integrates cancellation checks into CurlImpl (using libcurl progress callbacks and a 50ms polling interval), the REST retry loop, backoff mechanisms, and Storage operations (bypassing read hedging). The reviewer feedback highlights opportunities to optimize performance and style by using get_optional on Options to avoid redundant map lookups in RestCancellationWait, IsRestCancelled, and CurlImpl, and suggests directly including the <optional> header in rest_cancellation.h.

Comment thread google/cloud/internal/curl_impl.cc Resolved
@colinmoy

Copy link
Copy Markdown
Collaborator

/gcbrun

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.09028% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.63%. Comparing base (0e799e5) to head (831b82d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/internal/rest_retry_loop_test.cc 92.10% 3 Missing ⚠️
google/cloud/internal/curl_impl.cc 93.54% 2 Missing ⚠️
google/cloud/storage/internal/connection_impl.cc 84.61% 2 Missing ⚠️
...cloud/storage/internal/retry_object_read_source.cc 90.00% 2 Missing ⚠️
google/cloud/internal/rest_cancellation.h 94.73% 1 Missing ⚠️
...e/cloud/storage/internal/rest/cancellation_test.cc 99.77% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16663    +/-   ##
========================================
  Coverage   92.62%   92.63%            
========================================
  Files        2271     2274     +3     
  Lines      224597   225163   +566     
========================================
+ Hits       208032   208573   +541     
- Misses      16565    16590    +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants