Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions internal/client/balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1805,7 +1805,7 @@ func (b *Balancer) hasLossSignalLocked() bool {
continue
}
sent, _, _, _, _ := stats.snapshot()
if sent >= 5 {
if sent > 0 {
return true
}
}
Expand All @@ -1819,7 +1819,7 @@ func (b *Balancer) hasLatencySignalLocked() bool {
continue
}
_, _, _, _, count := stats.snapshot()
if count >= 5 {
if count > 0 {
return true
}
}
Expand Down Expand Up @@ -2032,13 +2032,10 @@ func (b *Balancer) leastLossTopTierCandidatesLocked(excludeKey string) []Connect

func (b *Balancer) lossScoreLocked(idx int) uint64 {
if idx < 0 || idx >= len(b.stats) || b.stats[idx] == nil {
return 200 // Use a more neutral default for unknown
return 0
}
sent, _, lost, _, _ := b.stats[idx].snapshot()
if sent < 5 {
return 200 // Initial probation
}
if lost == 0 {
if sent == 0 || lost == 0 {
return 0
}
return (lost * 1000) / sent
Expand All @@ -2049,7 +2046,7 @@ func (b *Balancer) latencyScoreLocked(idx int) uint64 {
return 999000
}
_, _, _, sum, count := b.stats[idx].snapshot()
if count < 5 {
if count == 0 {
return 999000
Comment thread
taskkillstar marked this conversation as resolved.
}
return sum / count
Expand Down
31 changes: 31 additions & 0 deletions internal/client/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,34 @@ func TestBalancerSetConnectionMTUUpdatesBalancerOnly(t *testing.T) {
t.Fatalf("expected snapshot MTUs to update, got up=%d chars=%d down=%d", got.UploadMTUBytes, got.UploadMTUChars, got.DownloadMTUBytes)
}
}

func TestBalancerLossThenLatency_NoProbationStarvation(t *testing.T) {
b := NewBalancer(BalancingLossThenLatency, nil)
connections := []*Connection{
{Key: "slow-established", IsValid: true},
{Key: "fast-new", IsValid: true},
}
b.SetConnections(connections)
_ = b.SetConnectionValidity("slow-established", true)
_ = b.SetConnectionValidity("fast-new", true)

// "slow-established" has 10 packets, 0 loss, 600ms latency
for i := 0; i < 10; i++ {
b.ReportSend("slow-established")
b.ReportSuccess("slow-established", 600*time.Millisecond)
}

// "fast-new" has 2 packets, 0 loss, 45ms latency (previously trapped under sent < 5 probation)
for i := 0; i < 2; i++ {
b.ReportSend("fast-new")
b.ReportSuccess("fast-new", 45*time.Millisecond)
}

best, ok := b.GetBestConnection()
if !ok {
t.Fatal("expected a valid connection")
}
if best.Key != "fast-new" {
t.Fatalf("expected fast newly reactivated resolver to be picked, got %q", best.Key)
}
}