-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
proposal: add cause to canceled context when Client sending a RST_STREAM due to an error on their end #7778
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7778 +/- ##
==========================================
- Coverage 81.80% 81.79% -0.02%
==========================================
Files 374 375 +1
Lines 37978 37985 +7
==========================================
Hits 31068 31068
- Misses 5605 5608 +3
- Partials 1305 1309 +4
|
fedc451
to
f1793eb
Compare
@dastrobu thanks for the PR. Apologies for getting late to it. These are too many errors to verify at once. Could you just narrow down this PR to one case? Perhaps only to RstStream code from server? Also, please describe in the PR (only for RST case) what is the limitation and how this change improves that. Also, not sure if we should have a separate function to create context. We need to have this change easy to just do natively. Like adding the cancelCause only when we need to and it should be left on the author of code to decide. Let me know what you think. If you want, in the description of the related issue we can link the error cases you have identified |
@dastrobu let's narrow down this PR to only "Client sending a RST_STREAM due to an error on their end". We want to see how much change it is and if it has enough benefit to reason about. Thanks |
@dastrobu ping on this if you have bandwidth for making the the change. Thanks |
@purnesh42H I will update the PR draft later this week. |
e0753ce
to
67fded0
Compare
I narrowed it down and added an example.
PR description was updated.
I extracted the function here to dry out code and make the logic it testable through unit tests (see Hence, the cancel function must always be of the same type. We could inline the
I am not sure I understand what error cases you mean here? |
67fded0
to
a09df44
Compare
Can I request that we first enumerate all the reasons the grpc server might cancel the context? I can think of:
I'm not sure about "internal error" mentioned in the first comment. Can you give an example of this? After that, what would knowing the difference between these cases affect? Is this purely for monitoring/alerting/metrics? |
Closes grpc#7541 � Conflicts: � internal/transport/transport.go
d105c77
to
59a52b7
Compare
… with a http2 error code. Signed-off-by: Daniel Strobusch <[email protected]>
Signed-off-by: Daniel Strobusch <[email protected]>
59a52b7
to
a9a5167
Compare
@dfawley thanks for the prompt reply. I will pick that up tomorrow and try to write up the cases in #7541 |
I have updated the Additional Context section in issue #7541 with the previously mentioned cases. I hope this is helpful. We can continue the discussion here or in the issue. |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Related Issue: #7541
Summary:
This PR introduces a feature to add a cause to the context cancellation, for example when a client sends an RST_STREAM frame. This enhancement aims to provide more transparency and ease debugging by distinguishing between different reasons for context cancellation.
Use Case:
When a client resets a connection, the
http2_server
cancels the current context to interrupt all server internal processing. However, it is challenging to determine the exact reason for the context cancellation, whether it was due to an internal error, a timeout, or a client sending an RST frame. This feature will help in identifying the cause of the context cancellation, making it easier to debug and handle errors appropriately.Proposed Solution:
context.CancelFunc
withcontext.CancelCauseFunc
.Additional Context:
This change is backward-compatible and does not affect existing application code that checks for
ctx.Err()
. The newcontext.Cause(ctx)
method will provide additional information when available.Example:
The PR adds an example which shows how to implement a server with asynchronous processing using goroutines.
The example illustrates some client behaviors (RST frame, close connection, timeout) which are propagated to the worker goroutine through the context.
Here are the logs of the example server (with comments):
Open Issues
Http2CodeError
) has been added to illustrate how server implementations could do error matching. The design for error types could be discussed in more detail. I'd see more error cases in the future that could be propagated through the context (e.g.ConnectionClosed
by client,GrpcTimeout
to distinguish from other timeouts).