Skip to content
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

test: fix potential goroutine leak in TestUpdateAddresses_RetryFromFirstAddr #5023

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions clientconn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,12 +857,15 @@ func (s) TestUpdateAddresses_RetryFromFirstAddr(t *testing.T) {
defer lis3.Close()

closeServer2 := make(chan struct{})
exitCh := make(chan struct{})
server1ContactedFirstTime := make(chan struct{})
server1ContactedSecondTime := make(chan struct{})
server2ContactedFirstTime := make(chan struct{})
server2ContactedSecondTime := make(chan struct{})
server3Contacted := make(chan struct{})

defer close(exitCh)

// Launch server 1.
go func() {
// First, let's allow the initial connection to go READY. We need to do
Expand All @@ -886,12 +889,18 @@ func (s) TestUpdateAddresses_RetryFromFirstAddr(t *testing.T) {
// until balancer is built to process the addresses.
stateNotifications := testBalancerBuilder.nextStateNotifier()
// Wait for the transport to become ready.
for s := range stateNotifications {
if s == connectivity.Ready {
break
for {
select {
case st := <-stateNotifications:
if st == connectivity.Ready {
goto ready
}
case <-exitCh:
return
}
}

ready:
// Once it's ready, curAddress has been set. So let's close this
// connection prompting the first reconnect cycle.
conn1.Close()
Expand Down