-
Notifications
You must be signed in to change notification settings - Fork 536
fix(grpc): finish aio client spans on abandoned calls #19716
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -224,7 +224,6 @@ async def _wrap_stream_response( | |
| span: Span, | ||
| ) -> ResponseIterableType: | ||
| try: | ||
| _handle_add_callback(call, _done_callback_stream(span)) | ||
| async for response in call: | ||
| yield response | ||
| except StopAsyncIteration: | ||
|
|
@@ -264,6 +263,9 @@ async def _wrap_unary_response( | |
| # So we can't handle the error in done callbacks. | ||
| _handle_rpc_error(span, rpc_error) | ||
| raise | ||
| except asyncio.CancelledError: | ||
| span.finish() | ||
| raise | ||
|
|
||
|
|
||
| class _UnaryUnaryClientInterceptor(aio.UnaryUnaryClientInterceptor, _ClientInterceptor): | ||
|
|
@@ -293,6 +295,7 @@ async def intercept_unary_stream( | |
| client_call_details, | ||
| ) | ||
| call = await continuation(client_call_details, request) | ||
| _handle_add_callback(call, _done_callback_stream(span)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If the returned unary-stream or stream-stream wrapper is never iterated and the RPC terminates with cancellation, a deadline, or a server error, this newly registered callback reaches AGENTS.md reference: AGENTS.md:L67-L70 Useful? React with 👍 / 👎. |
||
| return self._wrap_stream_response(call, span) | ||
|
|
||
|
|
||
|
|
@@ -323,4 +326,5 @@ async def intercept_stream_stream( | |
| client_call_details, | ||
| ) | ||
| call = await continuation(client_call_details, request_iterator) | ||
| _handle_add_callback(call, _done_callback_stream(span)) | ||
| return self._wrap_stream_response(call, span) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| fixes: | ||
| - | | ||
| grpc: Fixes an issue where cancelled or unconsumed asynchronous client calls retain unfinished tracing spans. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a unary-unary or stream-unary operation is cancelled, including the new
asyncio.wait_fortimeout case, this branch flushes the span without settinggrpc.status.code, the error flag, or error details, so the failed RPC is reported as a successful span. Streaming cancellations already use_handle_cancelled_errorand are asserted asStatusCode.CANCELLEDwitherror == 1; apply equivalent cancellation metadata here before finishing.Useful? React with 👍 / 👎.