diff --git a/tsdb/head_append.go b/tsdb/head_append.go index 005d20b720..91134daa13 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -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