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

jiajunwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 1174926  Fix a potential race condition in MBean unregister logic.
1174926 is described below

commit 1174926e423b427d4fe31d0edfad0dd953e5ace0
Author: Jiajun Wang <[email protected]>
AuthorDate: Wed Sep 1 10:43:07 2021 -0700

    Fix a potential race condition in MBean unregister logic.
    
    The unregister method should relies on the MBeanServer class to validate if 
the target MBean has been unregistered or not to avoid race condition.
---
 .../java/org/apache/helix/monitoring/mbeans/MBeanRegistrar.java     | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git 
a/metrics-common/src/main/java/org/apache/helix/monitoring/mbeans/MBeanRegistrar.java
 
b/metrics-common/src/main/java/org/apache/helix/monitoring/mbeans/MBeanRegistrar.java
index 22bd516..28ff99c 100644
--- 
a/metrics-common/src/main/java/org/apache/helix/monitoring/mbeans/MBeanRegistrar.java
+++ 
b/metrics-common/src/main/java/org/apache/helix/monitoring/mbeans/MBeanRegistrar.java
@@ -21,6 +21,7 @@ package org.apache.helix.monitoring.mbeans;
 
 import java.lang.management.ManagementFactory;
 import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
@@ -84,10 +85,13 @@ public class MBeanRegistrar {
   }
 
   public static void unregister(ObjectName objectName) {
-    if (objectName != null && _beanServer.isRegistered(objectName)) {
+    if (objectName != null) {
       try {
         _beanServer.unregisterMBean(objectName);
         LOG.info("MBean {} has been un-registered.", 
objectName.getCanonicalName());
+      } catch (InstanceNotFoundException ex) {
+        LOG.warn("MBean {} does not exist. It might have been removed 
already.",
+            objectName.getCanonicalName());
       } catch (JMException e) {
         LOG.warn("Error in un-registering: " + objectName.getCanonicalName(), 
e);
       }

Reply via email to