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

jbonofre pushed a commit to branch activemq-5.19.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-5.19.x by this push:
     new 589fcfc966 AMQ-9843 Handle InstanceNotFoundException during MBean 
unregistration to avoid errors on shutdown
589fcfc966 is described below

commit 589fcfc966b99350f5bdc75dbb34aff3dc7210c9
Author: Jean-Louis Monteiro <[email protected]>
AuthorDate: Tue Jan 27 12:38:32 2026 +0100

    AMQ-9843 Handle InstanceNotFoundException during MBean unregistration to 
avoid errors on shutdown
---
 .../activemq/broker/jmx/ManagementContext.java     | 24 ++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git 
a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
 
b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
index 7ef4529308..28c6f8c3d0 100644
--- 
a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
+++ 
b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ManagementContext.java
@@ -203,10 +203,16 @@ public class ManagementContext implements Service {
             // unregister the mbeans we have registered
             if (mbeanServer != null) {
                 for (Map.Entry<ObjectName, ObjectName> entry : 
registeredMBeanNames.entrySet()) {
-                    ObjectName actualName = entry.getValue();
+                    final ObjectName actualName = entry.getValue();
                     if (actualName != null && 
beanServer.isRegistered(actualName)) {
-                        LOG.debug("Unregistering MBean {}", actualName);
-                        mbeanServer.unregisterMBean(actualName);
+                        try {
+                            LOG.debug("Unregistering MBean {}", actualName);
+                            mbeanServer.unregisterMBean(actualName);
+                        } catch (javax.management.InstanceNotFoundException e) 
{
+                            // Ignore - the MBean was already unregistered 
(likely by advisory cleanup)
+                            // This is a benign race condition during shutdown
+                            LOG.trace("MBean already unregistered: {}", 
actualName);
+                        }
                     }
                 }
             }
@@ -449,10 +455,16 @@ public class ManagementContext implements Service {
      * Unregister an MBean
      */
     public void unregisterMBean(ObjectName name) throws JMException {
-        ObjectName actualName = this.registeredMBeanNames.get(name);
+        final ObjectName actualName = this.registeredMBeanNames.get(name);
         if (beanServer != null && actualName != null && 
beanServer.isRegistered(actualName) && this.registeredMBeanNames.remove(name) 
!= null) {
-            LOG.debug("Unregistering MBean {}", actualName);
-            beanServer.unregisterMBean(actualName);
+            try {
+                LOG.debug("Unregistering MBean {}", actualName);
+                beanServer.unregisterMBean(actualName);
+            } catch (javax.management.InstanceNotFoundException e) {
+                // Ignore - the MBean was already unregistered (race condition 
during concurrent cleanup)
+                // This is benign since the MBean is already gone, which is 
what we wanted
+                LOG.trace("MBean already unregistered: {}", actualName);
+            }
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to