Avoid race conditions in call-with-duration-metric

This commit is contained in:
Christopher Baines 2020-12-10 09:43:04 +00:00
parent f661edf72d
commit 9d39235cc8

View file

@ -371,6 +371,11 @@ The metric with the name @var{metric-name} is fetched from the
@var{registry}, or created if it doesn't already exist.
"
(let* ((metric
(or (metrics-registry-fetch-metric registry metric-name)
(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
@ -378,7 +383,7 @@ The metric with the name @var{metric-name} is fetched from the
#:buckets buckets
#:docstring docstring
#:labels labels
#:label-preset-values label-preset-values)))
#:label-preset-values label-preset-values)))))
(start-time (get-internal-real-time)))
(call-with-values
thunk