-
Notifications
You must be signed in to change notification settings - Fork 29
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
Close ClientStreaming on context cancellation #152
Conversation
CloseRequest and CloseResponse must both be called before the span can be ended. Remove onCalledClose bool as it's easy to derive.
Is this really true? I think only FWIW, I also think that cancelling the context used to create the RPC can be done, instead of calling |
@jhump my understanding was context.AfterFunc would be a nice use case for this cleanup logic. |
This doesn't make sense to me. Once
Ooh, nice. Yeah that's the way to go. (And a build tag could be used to provide a more heavy-weight implementation for folks not running Go 1.21.) |
Use build tags to allow for !go1.21
@jhump updated with a context.AfterFunc impl. I think CloseRequest and CloseResponse will always be called but yep on CloseResponse return we should be closing and don't have to wait for CloseRequest as the ResponseBody close won't be able to continue sending requests. Related issue around recording metrics on ctx cancel: open-telemetry/opentelemetry-go#4671 |
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.
Minor nit about sync.Once
vs atomic.Bool
. Otherwise, LGTM.
@emcfarlane, looks like there are merge conflicts from #153 that must be addressed |
Fix a data race for a streaming client on close when a the context is cancelled. This was introduced in #152 where we changed the behaviour to trigger a close on context cancellation. The state must be locked to avoid a data race with Send/Receive calls. Closes #170, #171. --------- Signed-off-by: Edward McFarlane <emcfarlane@buf.build>
CloseRequest and CloseResponse must both be called before the span can be ended. Remove onCloseCalled bool as it's easy to derive.
Updates
On
CloseResponse
we must have stopped the connection and it is now safe to close the span. To handle context cancellation and ensure the span is always closedcontext.AfterFunc
is added with a simpler backport for !go1.21.