Repository navigation
Classify gRPC cancellation as ClientCancelled - #923
KirillKurdyukov wants to merge 2 commits into
Conversation
Treat transport-originated stream cancellation as ConnectionLost so existing retry and reconnect handling can recover. Preserve explicit caller and stream cancellation, and cover Query and Topic streams with real gRPC regressions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #923 +/- ##
==========================================
+ Coverage 82.67% 82.78% +0.10%
==========================================
Files 99 99
Lines 12961 12985 +24
Branches 1269 1273 +4
==========================================
+ Hits 10716 10749 +33
+ Misses 1794 1789 -5
+ Partials 451 447 -4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
Связанный issue: #935. Для автоматического закрытия при влитии добавьте |
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by an unresolved moderate connection-eviction bug on synchronous transport cancellation, with an additional tracing-status mapping omission.
2 open issues
What changed in this PR
This pull request distinguishes transport-level gRPC cancellation from YDB server-side cancellation, enabling retries for idempotent operations while preserving explicit caller cancellation and deadline behavior across synchronous and asynchronous APIs.
Changes:
- Added
ClientCancelledandStatusCode.CLIENT_CANCELLED. - Updated cancellation classification, retry behavior, stream cleanup, and disconnect callbacks.
- Added regression coverage and documented the new exception and retry semantics.
| File | Description |
|---|---|
ydb/issues.py |
Defines the new client-cancellation status and exception. |
ydb/connection.py |
Maps synchronous gRPC cancellation and updates stream cancellation handling. |
ydb/aio/connection.py |
Separates async gRPC read cancellation from caller-task cancellation. |
ydb/_utilities_test.py |
Adds cancellation, deadline, retry, callback, and stream regression tests. |
ydb/_errors.py |
Implements idempotency-based retry behavior for ClientCancelled. |
docs/errors.rst |
Documents the exception hierarchy and retry policies. |
docs/apireference.rst |
Exposes ClientCancelled in the API reference. |
CHANGELOG.md |
Records the user-visible cancellation behavior change. |
Review effort: Lite
| return issues.Unimplemented("Method or feature is not implemented on server!") | ||
| elif rpc_error.code() == grpc.StatusCode.CANCELLED: | ||
| return issues.Cancelled(rpc_error.details()) | ||
| return issues.ClientCancelled(rpc_error.details()) |
| DEADLINE_EXCEEDED = _TRANSPORT_STATUSES_FIRST + 30 | ||
| CLIENT_INTERNAL_ERROR = _TRANSPORT_STATUSES_FIRST + 40 | ||
| UNIMPLEMENTED = _TRANSPORT_STATUSES_FIRST + 50 | ||
| CLIENT_CANCELLED = _TRANSPORT_STATUSES_FIRST + 60 |


Pull request type
What is the current behavior?
The SDK maps both gRPC
CANCELLEDand the YDB server'sCANCELLEDstatusto
ydb.Cancelled. Transport cancellation, including cancellation when achannel closes during node restarts, is therefore not retried for idempotent
operations unless the separate
retry_cancelledflag is enabled.Async gRPC reads can also raise
asyncio.CancelledError, bypassing thenormal YDB retry/reconnect classification.
What is the new behavior?
ydb.ClientCancelledwithStatusCode.CLIENT_CANCELLEDforgRPC cancellation. It inherits from
Cancelledto preserve existingexception handlers.
ClientCancelledwith fast backoff only whenidempotent=True,matching Java SDK cancellation policy.
retry_cancelled=Truedoes notoverride this requirement.
CANCELLEDstatus asCancelledwith its existingretry policy, and keep gRPC
DEADLINE_EXCEEDEDnon-retriable.Preserve explicit stream cancellation and caller-task cancellation, clean up
owned reads, and support optional disconnect callbacks.
Other information
This is the standalone SDK fix related to #921. Workflow, workload, metric and
baseline changes remain in #921.
Validation:
tox -e blacktox -e styletox -e mypytox -e py -- ydb -v: 307 passed with gRPC 1.85.0.sphinx-build -b html docs docs/_build/html -q: no new diagnostics.The regression tests cover transport and YDB cancellation, deadlines,
idempotency and
retry_cancelledcombinations, sync and async streams,explicit cancellation, optional callbacks, and public retry helpers.
Older local gRPC 1.78/1.82 environments exhibit an async channel-close hang,
also reproduced with the original PR iterator and test on gRPC 1.82.1.
The full unit suite retains the existing
Queue.getcleanup warning.Full YDB/chaos SLO was not run because the Docker daemon is unavailable.