From 26e74929e5305aec61c2f7c82b1bd0f2ad11f0c6 Mon Sep 17 00:00:00 2001 From: Kristofer Karlsson Date: Fri, 16 Jul 2021 13:25:41 +0200 Subject: [PATCH] Add synchronized around getCount dist usage Since TDigest objects are not thread safe, we need to protect reads from getting corrupted data or potentially throwing exceptions. --- .../com/spotify/metrics/core/SemanticMetricDistribution.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/spotify/metrics/core/SemanticMetricDistribution.java b/core/src/main/java/com/spotify/metrics/core/SemanticMetricDistribution.java index c45f453..5d45b2b 100644 --- a/core/src/main/java/com/spotify/metrics/core/SemanticMetricDistribution.java +++ b/core/src/main/java/com/spotify/metrics/core/SemanticMetricDistribution.java @@ -75,7 +75,7 @@ public ByteString getValueAndFlush() { @Override - public long getCount() { + public synchronized long getCount() { return distRef.get().size(); }