diff --git a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java index 124efe227a3b4..ce6acb0c9ace1 100644 --- a/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java +++ b/flink-metrics/flink-metrics-slf4j/src/main/java/org/apache/flink/metrics/slf4j/Slf4jReporter.java @@ -33,6 +33,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ConcurrentModificationException; import java.util.Map; /** @@ -75,6 +76,16 @@ public void close() { @Override public void report() { + try { + tryReport(); + } + catch (ConcurrentModificationException ignored) { + // at tryReport() we don't synchronize while iterating over the various maps which might cause a + // ConcurrentModificationException to be thrown, if concurrently a metric is being added or removed. + } + } + + private void tryReport() { // initialize with previous size to avoid repeated resizing of backing array // pad the size to allow deviations in the final string, for example due to different double value representations StringBuilder builder = new StringBuilder((int) (previousSize * 1.1));