Skip to content

Commit

Permalink
Add debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 14, 2024
1 parent 901c6f5 commit 1bedfa3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions common/dialer/default_parallel_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Di
if err != nil {
select {
case results <- dialResult{error: E.Cause(err, "dial ", iif.Name, " (", iif.Name, ")"), primary: primary}:
println("reterr", primary)
case <-returned:
println("retnil", primary)
}
} else {
select {
case results <- dialResult{Conn: conn}:
case results <- dialResult{Conn: conn, primary: primary}:
println("retconn", primary)
case <-returned:
println("retclose", primary)
conn.Close()
}
}
Expand All @@ -64,15 +68,18 @@ func (d *DefaultDialer) dialParallelInterface(ctx context.Context, dialer net.Di
for {
select {
case <-fallbackChan:
println("start fallback")
fallbackCtx, fallbackCancel := context.WithCancel(ctx)
defer fallbackCancel()
for _, iif := range fallbackInterfaces {
go startRacer(fallbackCtx, false, iif)
}
case res := <-results:
if res.error == nil {
println("return", res.primary)
return res.Conn, res.primary, nil
}
println("err", res.primary)
errors = append(errors, res.error)
if len(errors) == len(primaryInterfaces)+len(fallbackInterfaces) {
return nil, false, E.Errors(errors...)
Expand Down Expand Up @@ -108,16 +115,20 @@ func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, d
if err != nil {
select {
case results <- dialResult{error: E.Cause(err, "dial ", iif.Name, " (", iif.Name, ")"), primary: primary}:
println("freterr", primary)
case <-returned:
println("fretnil", primary)
}
} else {
select {
case results <- dialResult{Conn: conn}:
case results <- dialResult{Conn: conn, primary: primary}:
println("fretconn", primary)
case <-returned:
if primary && time.Since(startAt) <= fallbackDelay {
resetFastFallback(time.Time{})
}
conn.Close()
println("fretclose", primary)
}
}
}
Expand All @@ -134,8 +145,10 @@ func (d *DefaultDialer) dialParallelInterfaceFastFallback(ctx context.Context, d
select {
case res := <-results:
if res.error == nil {
println("freturn", res.primary)
return res.Conn, res.primary, nil
}
println("ferr", res.primary)
errors = append(errors, res.error)
if len(errors) == len(primaryInterfaces)+len(fallbackInterfaces) {
return nil, false, E.Errors(errors...)
Expand Down

0 comments on commit 1bedfa3

Please sign in to comment.