From 7c2fd4767db2dfe1e7eeb7bb69ba35e8aec22928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20St=C3=A4ber?= Date: Mon, 17 Oct 2022 15:42:03 +0200 Subject: [PATCH] Fix race condition with Exemplar in Counter --- prometheus/counter.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/prometheus/counter.go b/prometheus/counter.go index 40d1b24f3..3668a16b3 100644 --- a/prometheus/counter.go +++ b/prometheus/counter.go @@ -140,7 +140,8 @@ func (c *counter) get() float64 { } func (c *counter) Write(out *dto.Metric) error { - + // Read the Exemplar first and the value second. This is to avoid a race condition + // where users see an exemplar for a not-yet-existing observation. var exemplar *dto.Exemplar if e := c.exemplar.Load(); e != nil { exemplar = e.(*dto.Exemplar)