asfgit closed pull request #7008: [FLINK-10715][metrics] Suppress 
ConcurrentModificationException thrown by the Slf4jReporter
URL: https://github.com/apache/flink/pull/7008
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 124efe227a3..ce6acb0c9ac 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));


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to