fix(timesync): queryMultipleHttp hanging if all servers are unreachable

This commit is contained in:
Siyuan Miao 2025-06-13 00:33:43 +02:00
parent b822b73a03
commit 27acff1b69
1 changed files with 12 additions and 1 deletions

View File

@ -95,16 +95,27 @@ func (t *TimeSync) queryMultipleHttp(urls []string, timeout time.Duration) (now
} else if errors.Is(err, context.Canceled) { } else if errors.Is(err, context.Canceled) {
metricHttpCancelCount.WithLabelValues(url).Inc() metricHttpCancelCount.WithLabelValues(url).Inc()
metricHttpTotalCancelCount.Inc() metricHttpTotalCancelCount.Inc()
results <- nil
} else { } else {
scopedLogger.Warn(). scopedLogger.Warn().
Str("error", err.Error()). Str("error", err.Error()).
Int("status", status). Int("status", status).
Msg("failed to query HTTP server") Msg("failed to query HTTP server")
results <- nil
} }
}(url) }(url)
} }
return <-results for range urls {
result := <-results
if result == nil {
continue
}
now = result
return
}
return
} }
func queryHttpTime( func queryHttpTime(