This commit is contained in:
Arve Knudsen 2026-02-03 13:17:01 -05:00 committed by GitHub
commit 87fffeb837
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,7 @@ import (
"fmt"
"log/slog"
"math"
"runtime"
"time"
"github.com/prometheus/prometheus/model/exemplar"
@ -120,12 +121,18 @@ func (h *Head) initTime(t int64) {
if !h.minTime.CompareAndSwap(math.MaxInt64, t) {
// Concurrent appends that are initializing.
// Wait until h.maxTime is swapped to avoid minTime/maxTime races.
antiDeadlockTimeout := time.After(500 * time.Millisecond)
// This should complete in microseconds under normal operation.
antiDeadlockTimeout := time.After(100 * time.Millisecond)
for h.maxTime.Load() == math.MinInt64 {
select {
case <-antiDeadlockTimeout:
// This should never happen in normal operation.
// If it does, there may be a bug or the system is severely overloaded.
h.logger.Warn("initTime timeout waiting for maxTime initialization")
return
default:
// Yield to allow the initializing goroutine to complete.
runtime.Gosched()
}
}
return