Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release-v0.18 back into master #104

Merged
merged 4 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -22,6 +22,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR 85]: https://github.com/prometheus/client_rust/pull/85
[PR 96]: https://github.com/prometheus/client_rust/pull/96

## [0.18.1]

### Fixed

- Fix race condition in `Family::get_or_create`. See [PR 102].

[PR 102]: https://github.com/prometheus/client_rust/pull/102

## [0.18.0]

### Changed
Expand Down
11 changes: 7 additions & 4 deletions src/metrics/family.rs
Expand Up @@ -3,7 +3,7 @@
//! See [`Family`] for details.

use super::{MetricType, TypedMetric};
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard};
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::collections::HashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -223,11 +223,14 @@ impl<S: Clone + std::hash::Hash + Eq, M, C: MetricConstructor<M>> Family<S, M, C
}

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

drop(write_guard);
write_guard
.entry(label_set.clone())
.or_insert_with(|| self.constructor.new_metric());

RwLockReadGuard::map(self.metrics.read(), |metrics| {
let read_guard = RwLockWriteGuard::downgrade(write_guard);

RwLockReadGuard::map(read_guard, |metrics| {
metrics
.get(label_set)
.expect("Metric to exist after creating it.")
Expand Down