Skip to content

Commit 05bd55e

Browse files
author
1911860538
committed
net: fix dialSerial returns a non-first error
1 parent 24ff1bb commit 05bd55e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/net/dial.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,16 @@ func (sd *sysDialer) dialParallel(ctx context.Context, primaries, fallbacks addr
727727
// dialSerial connects to a list of addresses in sequence, returning
728728
// either the first successful connection, or the first error.
729729
func (sd *sysDialer) dialSerial(ctx context.Context, ras addrList) (Conn, error) {
730-
var conn Conn
731730
var firstErr error // The error from the first address is most relevant.
732731

733732
for i := range ras {
734-
conn, firstErr = sd.dialAddr(ctx, ras, i)
735-
if firstErr == nil {
733+
conn, err := sd.dialAddr(ctx, ras, i)
734+
if err == nil {
736735
return conn, nil
737736
}
737+
if firstErr == nil {
738+
firstErr = err
739+
}
738740
}
739741

740742
if firstErr == nil {

0 commit comments

Comments
 (0)