fix upstream selection when some upstream is not modified

This commit is contained in:
guochao 2025-02-06 00:55:29 +08:00
parent 19e491c5a6
commit 5f1d48391a

View File

@ -463,6 +463,7 @@ func (server *Server) fastesUpstream(r *http.Request, lastModified time.Time) (r
resultResponse, resultCh, resultErr = response, ch, err
notModifiedCh <- idx
})
logger.Debug("voted not modified")
return
}
@ -478,7 +479,7 @@ func (server *Server) fastesUpstream(r *http.Request, lastModified time.Time) (r
}
})
logger.Debug("voted")
logger.Debug("voted update")
}()
}
@ -486,14 +487,18 @@ func (server *Server) fastesUpstream(r *http.Request, lastModified time.Time) (r
resultIdx = -1
if idx, ok := <-updateCh; ok {
select {
case idx := <-updateCh:
resultIdx = idx
slog.With("upstreamIdx", resultIdx).Debug("upstream selected")
} else if idx, ok := <-notModifiedCh; ok {
resultIdx = idx
slog.With("upstreamIdx", resultIdx).Debug("upstream selected(not modified)")
} else {
slog.Debug("no valid upstream found")
default:
select {
case idx := <-notModifiedCh:
resultIdx = idx
slog.With("upstreamIdx", resultIdx).Debug("all upstream not modified")
default:
slog.Debug("no valid upstream found")
}
}
return