Skip to content

Commit 6597abc

Browse files
authored
Merge pull request #103 from mxinden/release-v0.18
*: Prepare v0.18.1
2 parents bf08e49 + ffd3c3e commit 6597abc

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.18.1]
8+
9+
### Fixed
10+
11+
- Fix race condition in `Family::get_or_create`. See [PR 102].
12+
13+
[PR 102]: https://github.com/prometheus/client_rust/pull/102
14+
715
## [0.18.0]
816

917
### Changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "prometheus-client"
3-
version = "0.18.0"
3+
version = "0.18.1"
44
authors = ["Max Inden <mail@max-inden.de>"]
55
edition = "2021"
66
description = "Open Metrics client library allowing users to natively instrument applications."

src/metrics/family.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! See [`Family`] for details.
44
55
use super::{MetricType, TypedMetric};
6-
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
6+
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
77
use std::collections::HashMap;
88
use std::sync::Arc;
99

@@ -222,11 +222,14 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
222222
}
223223

224224
let mut write_guard = self.metrics.write();
225-
write_guard.insert(label_set.clone(), self.constructor.new_metric());
226225

227-
drop(write_guard);
226+
write_guard
227+
.entry(label_set.clone())
228+
.or_insert_with(|| self.constructor.new_metric());
228229

229-
RwLockReadGuard::map(self.metrics.read(), |metrics| {
230+
let read_guard = RwLockWriteGuard::downgrade(write_guard);
231+
232+
RwLockReadGuard::map(read_guard, |metrics| {
230233
metrics
231234
.get(label_set)
232235
.expect("Metric to exist after creating it.")

0 commit comments

Comments
 (0)