Skip to content

Commit db4cc9f

Browse files
test: Fix goroutine leak in TestParsedTarget_WithCustomDialer (#8698)
Fixes #8695 Fixes a goroutine leak in clientconn_parsed_target_test.go where TestParsedTarget_WithCustomDialer() could leave dialer goroutines blocked on sending to addrCh if the test finished early or stopped reading. This change replaces the blocking channel send with a select statement using a timeout/context to ensure goroutines can always exit. RELEASE NOTES: None
1 parent 7472d57 commit db4cc9f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clientconn_parsed_target_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,13 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) {
297297
for _, test := range tests {
298298
t.Run(test.target, func(t *testing.T) {
299299
addrCh := make(chan string, 1)
300-
dialer := func(_ context.Context, address string) (net.Conn, error) {
301-
addrCh <- address
302-
return nil, errors.New("dialer error")
300+
dialer := func(ctx context.Context, address string) (net.Conn, error) {
301+
select {
302+
case addrCh <- address:
303+
return nil, errors.New("dialer error")
304+
case <-ctx.Done():
305+
return nil, ctx.Err()
306+
}
303307
}
304308

305309
cc, err := NewClient(test.target, WithTransportCredentials(insecure.NewCredentials()), withDefaultScheme(defScheme), WithContextDialer(dialer))

0 commit comments

Comments
 (0)