aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2020-12-10 09:43:04 +0000
committerChristopher Baines <mail@cbaines.net>2020-12-10 09:43:04 +0000
commit9d39235cc84407b662f509f72aa2ff64f779f676 (patch)
treeced88fb0501b00040804fa67698374fa6487575d
parentf661edf72d2dd711dffe4313c2a9360e79b36dd1 (diff)
downloadprometheus-9d39235cc84407b662f509f72aa2ff64f779f676.tar
prometheus-9d39235cc84407b662f509f72aa2ff64f779f676.tar.gz
Avoid race conditions in call-with-duration-metric
-rw-r--r--prometheus.scm19
1 files changed, 12 insertions, 7 deletions
diff --git a/prometheus.scm b/prometheus.scm
index e0f58f6..bae0695 100644
--- a/prometheus.scm
+++ b/prometheus.scm
@@ -372,13 +372,18 @@ The metric with the name @var{metric-name} is fetched from the
"
(let* ((metric
(or (metrics-registry-fetch-metric registry metric-name)
- (make-histogram-metric
- registry
- metric-name
- #:buckets buckets
- #:docstring docstring
- #:labels labels
- #:label-preset-values label-preset-values)))
+ (monitor
+ ;; Check once more in case another thread has created
+ ;; the metric while this thread was waiting for the
+ ;; mutex
+ (or (metrics-registry-fetch-metric registry metric-name)
+ (make-histogram-metric
+ registry
+ metric-name
+ #:buckets buckets
+ #:docstring docstring
+ #:labels labels
+ #:label-preset-values label-preset-values)))))
(start-time (get-internal-real-time)))
(call-with-values
thunk