-
Notifications
You must be signed in to change notification settings - Fork 4.6k
clientconn: Wait for health check when closing the transport #8783
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: master
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8783 +/- ##
==========================================
- Coverage 83.33% 83.29% -0.04%
==========================================
Files 418 418
Lines 32910 32921 +11
==========================================
- Hits 27424 27421 -3
- Misses 4088 4095 +7
- Partials 1398 1405 +7
🚀 New features to boost your workflow:
|
clientconn.go
Outdated
| func (ac *addrConn) createTransport(ctx context.Context, addr resolver.Address, copts transport.ConnectOptions, connectDeadline time.Time) error { | ||
| addr.ServerName = ac.cc.getServerName(addr) | ||
|
|
||
| var healthCheckDone <-chan struct{} |
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.
I think healthCheckCh and healthCheckDoneCh might be slightly better variable names to indicate that these are channels.
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.
Done.
|
|
||
| ac.mu.Lock() | ||
| defer ac.mu.Unlock() | ||
| defer func() { |
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.
Can you add a small note stating where the healthCheckComplete is set and why do we wait on healthCheckComplete instead of healthCheckDone.
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.
Added some comments. Hope they're helpful.
The health check goroutine could outlive a call to ClientConn.close(). Add a done channel that will be waited on when closing the transport. RELEASE NOTES: - Closing a client connection will now block until the health check goroutine completes. Signed-off-by: Tom Wieczorek <[email protected]>
bfd0214 to
599fb48
Compare
|
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. |
eshitachandwani
left a comment
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.
Adding @easwars as a second reviewer
| func (ac *addrConn) createTransport(ctx context.Context, addr resolver.Address, copts transport.ConnectOptions, connectDeadline time.Time) error { | ||
| addr.ServerName = ac.cc.getServerName(addr) | ||
|
|
||
| var healthCheckDoneCh <-chan struct{} |
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.
Instead of having two channels (where one is a copy of another, and we depend on nil checks to figure out if the associated event is something that will happen and therefore we should wait for it), what do you think about the following approach, which uses the grpcsync.Event type defined here:
grpc-go/internal/grpcsync/event.go
Line 28 in c05cfb3
| type Event struct { |
The grpcsync.Event is simply a wrapper around a channel and a boolean. So, you can check if the event has fired with one of its methods and you can wait for an event to fire with another of its methods.
- Make
startHealthCheckreturns twogrpcsync.Events- One for the health check goroutine started event
startHealthCheckwill fire this event right before starting the health check goroutine
- Another for the health check goroutine completed event
startHealthCheckwill fire this event as a deferred statement from inside the health check goroutine
- One for the health check goroutine started event
- In
createTransport- We can check in a
deferthat if the health check goroutine was started using the first of the above two events, and if the health check goroutine was not stated at all, then we can cancel thehctx - In
onClose, we will wait for the health check goroutine completed event if and only if the health check goroutine was started.
- We can check in a
Let me know what you think about this approach. Thanks.
|
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. |
|
Will revisit this next week, hopefully. |
The health check goroutine could outlive a call to
ClientConn.close(). Add a done channel that will be waited on when closing the transport.See:
RELEASE NOTES: