]> git.feebdaed.xyz Git - 0xmirror/grpc-go.git/commitdiff
test: Fix goroutine leak in TestParsedTarget_WithCustomDialer (#8698)
authorPranjali-2501 <87357388+Pranjali-2501@users.noreply.github.com>
Mon, 10 Nov 2025 10:30:18 +0000 (16:00 +0530)
committerGitHub <noreply@github.com>
Mon, 10 Nov 2025 10:30:18 +0000 (16:00 +0530)
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

clientconn_parsed_target_test.go

index 751343969534da1883fb727e446d37e0e2cbd1de..00e8e283f63ff017096b63a4cdfb03b8c7951b40 100644 (file)
@@ -297,9 +297,13 @@ func (s) TestParsedTarget_WithCustomDialer(t *testing.T) {
        for _, test := range tests {
                t.Run(test.target, func(t *testing.T) {
                        addrCh := make(chan string, 1)
-                       dialer := func(_ context.Context, address string) (net.Conn, error) {
-                               addrCh <- address
-                               return nil, errors.New("dialer error")
+                       dialer := func(ctx context.Context, address string) (net.Conn, error) {
+                               select {
+                               case addrCh <- address:
+                                       return nil, errors.New("dialer error")
+                               case <-ctx.Done():
+                                       return nil, ctx.Err()
+                               }
                        }
 
                        cc, err := NewClient(test.target, WithTransportCredentials(insecure.NewCredentials()), withDefaultScheme(defScheme), WithContextDialer(dialer))