Skip to content

Commit 7d9aad3

Browse files
committed
wait allgoroutines before exit from rtt check function
1 parent 7df09d1 commit 7d9aad3

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

internal/router/local_dc.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func checkFastestAddress(ctx context.Context, addresses []string) (string, error
3737
conn, err := dialer.DialContext(ctx, "tcp", address)
3838
if err == nil {
3939
results <- address
40+
cancel()
4041
} else {
4142
errs <- err
4243
}
@@ -46,14 +47,12 @@ func checkFastestAddress(ctx context.Context, addresses []string) (string, error
4647
}(addr)
4748
}
4849

49-
go func() {
50-
wg.Wait()
51-
close(results)
52-
close(errs)
53-
}()
54-
5550
close(startDial)
5651

52+
wg.Wait()
53+
close(results)
54+
close(errs)
55+
5756
if res, ok := <-results; ok {
5857
return res, nil
5958
}

0 commit comments

Comments
 (0)