From 2aaf84e425b01665665365c6565ce8c4f299f540 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Fri, 6 Mar 2026 23:22:45 +0300 Subject: [PATCH] prober: fix unstable sort when latency within 10% and priorities equal Signed-off-by: NotAShelf Change-Id: I49fed694108cfb91ffe3ffad5c02c3a96a6a6964 --- internal/prober/prober.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/prober/prober.go b/internal/prober/prober.go index f6dc6f1..3dddb48 100644 --- a/internal/prober/prober.go +++ b/internal/prober/prober.go @@ -177,9 +177,11 @@ func (p *Prober) SortedByLatency() []*UpstreamHealth { if aDown != bDown { return bDown // non-down first } - // Within 10% latency difference: prefer lower priority number. + // Within 10% latency difference: prefer lower priority number, then lower latency. if b.EMALatency > 0 && math.Abs(a.EMALatency-b.EMALatency)/b.EMALatency < 0.10 { - return a.Priority < b.Priority + if a.Priority != b.Priority { + return a.Priority < b.Priority + } } return a.EMALatency < b.EMALatency })