fix the issue

This commit is contained in:
Para Dox
2025-06-01 18:08:55 +07:00
parent f6b2aa2206
commit 542aa60b23

View File

@@ -2806,6 +2806,10 @@ func handleRequest(w http.ResponseWriter, r *http.Request, backends []Backend, c
Method: displayMethod, Method: displayMethod,
} }
// Primary responses should ALWAYS be sent to the user (except HTTP errors >= 400)
// JSON-RPC errors from primary are valid responses that must be propagated
// The following checks only apply to secondary backends
// CRITICAL FIX: Only allow secondary backends to win if they have successful responses // CRITICAL FIX: Only allow secondary backends to win if they have successful responses
if b.Role == "secondary" && resp.StatusCode >= 400 { if b.Role == "secondary" && resp.StatusCode >= 400 {
// Secondary returned an error - DO NOT let it win the race // Secondary returned an error - DO NOT let it win the race
@@ -2924,6 +2928,9 @@ 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) { if responseHandled.CompareAndSwap(false, true) {
if enableDetailedLogs {
log.Printf("Backend %s won the race for method %s with status %d", b.Name, displayMethod, resp.StatusCode)
}
responseChan <- struct { responseChan <- struct {
backend string backend string
resp *http.Response resp *http.Response