-
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
transport : wait for goroutines to exit before transport closes #7666
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7666 +/- ##
==========================================
+ Coverage 81.85% 82.08% +0.23%
==========================================
Files 361 362 +1
Lines 27822 28119 +297
==========================================
+ Hits 22773 23081 +308
+ Misses 3851 3841 -10
+ Partials 1198 1197 -1
|
Thanks for addressing my earlier comments, overall change LGTM but still I feel it'd be better to add e2e style tests to verify the same. |
Yes, I am working on the tests for it. |
We rely on leak check to detect if |
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.
Looks good in general. Mostly nits.
internal/transport/transport_test.go
Outdated
// Tests that client does not close until the reader goroutine exits and closes | ||
// once reader goroutine returns. |
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.
// Tests that client does not close until the reader goroutine exits and closes | |
// once reader goroutine returns. | |
// Tests that closing a client transport does not return until the reader goroutine exits. |
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.
internal/transport/transport_test.go
Outdated
// Tests that client does not close until the reader goroutine exits and closes | ||
// once reader goroutine returns. | ||
func (s) TestClientCloseReturnsAfterReaderCompletes(t *testing.T) { | ||
connectCtx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
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.
Nit: s/connectCtx/ctx
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.
internal/transport/transport_test.go
Outdated
close(hangConn) | ||
select { | ||
case <-transportClosed: | ||
case <-time.After(defaultTestTimeout): |
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.
Nit: why not use ctx.Done()
here? That will ensure that the whole test has only 10s to run.
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.
This change is somehow causing a race condition between TestClientCloseReturnsEarlyWhenGoAwayWriteHangs
and TestClientCloseReturnsAfterReaderCompletes
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.
Hmm... That is weird. Tests should be independent. Do you have an output from a failed run?
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.
internal/transport/transport_test.go
Outdated
err := hc.Conn.Close() | ||
return err |
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.
Nit: single line return hc.Conn.Close()
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.
@@ -44,6 +44,7 @@ import ( | |||
) | |||
|
|||
const defaultTestTimeout = 10 * time.Second | |||
const defaultTestShortTimeout = 10 * time.Millisecond |
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.
Shouldn't we have a similar test to verify transport doesn't close until keepalive goroutine finish?
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.
We will not test that and leave that upto the leak checker becuase determining and controlling when keepalive
function closes is difficult with changing the actual function
(to add a testhook or something like that).
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 see. okay
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.
lgtm
Fixes: #2869
Previously,
clientconn.Close()
did not guarantee termination of some goroutines upon return.Now,
clientconn.Close()
ensures that:readerDone
channel to signal completion ofreader
goroutine.keepAliveDone
channel to signal completion ofkeepAlive
goroutine.clientconn.Close()
waits for all transports to be closed before returning.RELEASE NOTES:
clientconn.Close()
waits for all transports to be closed before returning.