From 7cf79509e30d17f4f0a51363f14593c2e390c833 Mon Sep 17 00:00:00 2001 From: Para Dox Date: Thu, 29 May 2025 18:52:08 +0700 Subject: [PATCH] may the force be with me --- benchmark-proxy/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/benchmark-proxy/main.go b/benchmark-proxy/main.go index 146535ae..3500895e 100644 --- a/benchmark-proxy/main.go +++ b/benchmark-proxy/main.go @@ -1946,7 +1946,24 @@ func handleRequest(w http.ResponseWriter, r *http.Request, backends []Backend, c } // Try to be the first to respond - if responseHandled.CompareAndSwap(false, true) { + // Primary backend always wins, secondary only wins with successful responses + shouldWin := false + if b.Role == "primary" { + // Primary backend always tries to win (whether success or error) + shouldWin = responseHandled.CompareAndSwap(false, true) + } else { + // Secondary backend only tries to win if response is successful + if resp.StatusCode < 400 { + shouldWin = responseHandled.CompareAndSwap(false, true) + } else { + // Secondary backend has error status, don't try to win + if enableDetailedLogs { + log.Printf("Secondary backend %s returned error status %d, not using response", b.Name, resp.StatusCode) + } + } + } + + if shouldWin { responseChan <- struct { backend string resp *http.Response