Skip to content

Commit

Permalink
chore: adjust error log
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyxim committed Mar 10, 2023
1 parent d309c63 commit 7cc1c1b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions component/dialer/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,17 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string,
go racer(ipv4s, preferIPVersion != 6)
go racer(ipv6s, preferIPVersion != 4)
var fallback dialResult
var err error
var errs []error
for {
select {
case <-ctx.Done():
if fallback.error == nil && fallback.Conn != nil {
return fallback.Conn, nil
}
return nil, fmt.Errorf("dual stack connect failed: %w", err)
if res, ok := <-results; ok && res.error == nil {
return res.Conn, nil
}
return nil, errorsJoin(errs...)
case <-fallbackTicker.C:
if fallback.error == nil && fallback.Conn != nil {
return fallback.Conn, nil
Expand All @@ -199,7 +202,11 @@ func dualStackDialContext(ctx context.Context, dialFn dialFunc, network string,
}
fallback = res
} else {
err = res.error
if res.isPrimary {
errs = append([]error{fmt.Errorf("connect failed: %w", res.error)}, errs...)
} else {
errs = append(errs, fmt.Errorf("connect failed: %w", res.error))
}
}
}
}
Expand Down Expand Up @@ -230,12 +237,12 @@ func parallelDialContext(ctx context.Context, network string, ips []netip.Addr,
for _, ip := range ips {
go racer(ctx, ip)
}
var err error
var errs []error
for {
select {
case <-ctx.Done():
if err != nil {
return nil, err
if len(errs) > 0 {
return nil, errorsJoin(errs...)
}
if ctx.Err() == context.DeadlineExceeded {
return nil, os.ErrDeadlineExceeded
Expand All @@ -245,7 +252,7 @@ func parallelDialContext(ctx context.Context, network string, ips []netip.Addr,
if res.error == nil {
return res.Conn, nil
}
err = res.error
errs = append(errs, res.error)
}
}
}
Expand Down

0 comments on commit 7cc1c1b

Please sign in to comment.