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

roachprod: fix leaky goroutine in SyncedCluster.Monitor #106341

Merged
merged 1 commit into from
Jul 7, 2023
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
7 changes: 5 additions & 2 deletions pkg/roachprod/install/cluster_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ func (c *SyncedCluster) Monitor(
ch := make(chan NodeMonitorInfo)
nodes := c.TargetNodes()
var wg sync.WaitGroup
monitorCtx, cancel := context.WithCancel(ctx)

for i := range nodes {
wg.Add(1)
Expand Down Expand Up @@ -758,9 +759,10 @@ done
return
}

// Watch for context cancellation.
// Watch for context cancellation, which can happen either if
// the test fails, or if the monitor loop exits.
go func() {
<-ctx.Done()
<-monitorCtx.Done()
sess.Close()
}()

Expand All @@ -776,6 +778,7 @@ done
}
go func() {
wg.Wait()
cancel()
close(ch)
}()

Expand Down