grpc
runtime_error
ai_generated
true
CANCELLED: grpc: 客户端流式调用被客户端取消
CANCELLED: grpc: client side streaming canceled by client
ID: grpc/client-side-streaming-cancel
80%修复率
85%置信度
1证据数
2024-01-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| gRPC Python 1.60+ | active | — | — | — |
| gRPC Java 1.60+ | active | — | — | — |
| gRPC Node 1.10+ | active | — | — | — |
根因分析
客户端显式取消了一个流式RPC(例如通过context取消或stream.CloseSend),在服务器完成处理之前,通常由于超时或提前退出。
English
Client explicitly cancels a streaming RPC (e.g., via context cancel or stream.CloseSend) before server finishes processing, often due to timeout or early exit.
官方文档
https://grpc.io/docs/guides/error-handling/解决方案
-
Check server-side handling of client cancel: ensure server reads from stream until EOF and handles context cancellation gracefully. In Python: for request in stub.StreamingCall(...): try: process(request) except grpc.RpcError as e: if e.code() == grpc.StatusCode.CANCELLED: break
-
Use a graceful shutdown pattern: before canceling, call stream.CloseSend() and wait for server response. In Go: if err := stream.CloseSend(); err != nil { log.Fatal(err) } for { _, err := stream.Recv(); if err == io.EOF { break } }
无效尝试
常见但无效的做法:
-
Adding longer timeouts to all RPCs
50% 失败
The cancellation is intentional from client logic; longer timeouts only mask the symptom and may cause resource leaks.
-
Ignoring the error and retrying immediately
60% 失败
Retrying without fixing the cancel logic may loop indefinitely or waste resources.