You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(promhttp): give coalesced callers independent metric slices
Concurrent callers sharing a coalesced Gather cycle previously received the same slice header. A caller that filtered or reordered its slice (for example applying name[] query parameters) could then race another caller of the same cycle. Each caller now gets its own slices.Clone; the MetricFamily values stay shared and read-only.
Also clarify the CoalesceGather documentation (shared-snapshot staleness, the Timeout interaction, and slice-versus-contents mutation) and tidy the sentinel error and coalescer test helpers.
Signed-off-by: Kemal Akkoyun <kemal.akkoyun@datadoghq.com>
Copy file name to clipboardExpand all lines: prometheus/promhttp/http.go
+33-11Lines changed: 33 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,7 @@ import (
37
37
"fmt"
38
38
"io"
39
39
"net/http"
40
+
"slices"
40
41
"strconv"
41
42
"sync"
42
43
"time"
@@ -96,7 +97,7 @@ type coalescingGatherer struct {
96
97
// gatherCycle tracks a single in-flight Gather and all HTTP handlers sharing it.
97
98
typegatherCyclestruct {
98
99
readychanstruct{} // closed when Gather completes; happens-before reads of mfs/err/done
99
-
mfs []*dto.MetricFamily// set before ready is closed; shared across handlers, must not be mutated
100
+
mfs []*dto.MetricFamily// canonical result, set before ready is closed; callers get a slices.Clone, the element values stay shared and must not be mutated
100
101
errerror// set before ready is closed
101
102
donefunc() // underlying done callback; set before ready is closed
102
103
refsint// number of handlers using this cycle; protected by coalescingGatherer.mu
0 commit comments