You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2023/03/17 05:03:37 UTC

[dubbo] branch 3.2 updated: gc bug (#11855)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new ec9eecfc82 gc bug (#11855)
ec9eecfc82 is described below

commit ec9eecfc821e6f56c5b1d1150d3a98a8509d969b
Author: wxbty <38...@users.noreply.github.com>
AuthorDate: Fri Mar 17 13:02:56 2023 +0800

    gc bug (#11855)
    
    Co-authored-by: x-shadow-man <14...@qq.com>
---
 .../apache/dubbo/metrics/report/AbstractMetricsReporter.java | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/report/AbstractMetricsReporter.java b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/report/AbstractMetricsReporter.java
index e88bd0cdc4..4a0558b387 100644
--- a/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/report/AbstractMetricsReporter.java
+++ b/dubbo-metrics/dubbo-metrics-default/src/main/java/org/apache/dubbo/metrics/report/AbstractMetricsReporter.java
@@ -17,6 +17,7 @@
 
 package org.apache.dubbo.metrics.report;
 
+import io.micrometer.core.instrument.binder.MeterBinder;
 import org.apache.dubbo.common.URL;
 import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
 import org.apache.dubbo.common.constants.MetricsConstants;
@@ -65,6 +66,8 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
     protected final URL url;
     @SuppressWarnings("rawtypes")
     protected final List<MetricsCollector> collectors = new ArrayList<>();
+    // Avoid instances being gc due to weak references
+    protected final List<MeterBinder> instanceHolder = new ArrayList<>();
     public static final CompositeMeterRegistry compositeRegistry = new CompositeMeterRegistry();
 
     private final ApplicationModel applicationModel;
@@ -116,12 +119,17 @@ public abstract class AbstractMetricsReporter implements MetricsReporter {
             jvmGcMetrics.bindTo(compositeRegistry);
             Runtime.getRuntime().addShutdownHook(new Thread(jvmGcMetrics::close));
 
-            new ProcessorMetrics(extraTags).bindTo(compositeRegistry);
+            bindTo(new ProcessorMetrics(extraTags));
             new JvmThreadMetrics(extraTags).bindTo(compositeRegistry);
-            new UptimeMetrics(extraTags).bindTo(compositeRegistry);
+            bindTo(new UptimeMetrics(extraTags));
         }
     }
 
+    private void bindTo(MeterBinder binder) {
+        binder.bindTo(compositeRegistry);
+        instanceHolder.add(binder);
+    }
+
     @SuppressWarnings("rawtypes")
     private void initCollectors() {
         ScopeBeanFactory beanFactory = applicationModel.getBeanFactory();