may the force be with me

This commit is contained in:
Para Dox
2025-05-29 18:52:08 +07:00
parent 6d46471536
commit 7cf79509e3

View File

@@ -1946,7 +1946,24 @@ func handleRequest(w http.ResponseWriter, r *http.Request, backends []Backend, c
} }
// Try to be the first to respond // 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 { responseChan <- struct {
backend string backend string
resp *http.Response resp *http.Response