Skip to content

FELIX-6824 - Fix JMX MBean leak during Jetty restart cycle#482

Merged
paulrutter merged 1 commit intoapache:masterfrom
francescomari:fix/jmx-mbean-leak-on-restart
Mar 12, 2026
Merged

FELIX-6824 - Fix JMX MBean leak during Jetty restart cycle#482
paulrutter merged 1 commit intoapache:masterfrom
francescomari:fix/jmx-mbean-leak-on-restart

Conversation

@francescomari
Copy link
Contributor

Summary

When stopJetty() runs during a configuration-triggered restart, Jetty's JMX MBeans are not unregistered before the Server is stopped. On the subsequent startJetty(), the new Server creates a new MBeanServerTracker which tries to register org.eclipse.jetty.server:type=server,id=0 — but the old registration still exists, causing an InstanceAlreadyExistsException.

Root cause

Two issues:

  1. JettyService.stopJetty() closes the MBeanServerTracker after server.stop(). By the time the tracker is closed, the server's component tree has already been torn down, so MBeanContainer can no longer walk the tree to unregister its MBeans. They remain in the platform MBeanServer as stale entries.

  2. MBeanServerTracker.removedService() removes the MBeanContainer as an event listener and calls super.removedService(), but never calls MBeanContainer.destroy(). Without destroy(), the container does not unregister the MBeans it previously registered.

Changes

  • JettyService.stopJetty() (both jetty and jetty12): move mbeanServerTracker.close() before server.stop() so the tracker is closed while the server's component tree is still intact and MBeans can be properly unregistered
  • MBeanServerTracker.removedService() (both jetty and jetty12): call service.destroy() before removing the event listener, so MBeanContainer unregisters all MBeans it owns

Call MBeanContainer.destroy() in MBeanServerTracker.removedService() to
unregister all JMX MBeans before removing the event listener. Also move
the MBeanServerTracker cleanup in stopJetty() to before server.stop()
so MBeans are unregistered while the Server instance is still valid.

Without this fix, restarting Jetty leaves stale MBean registrations
(e.g. org.eclipse.jetty.server:type=server,id=0) in the platform
MBeanServer, causing an InstanceAlreadyExistsException on the next
startup cycle.
Copy link
Contributor

@paulrutter paulrutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, two comments un the PR

@paulrutter paulrutter merged commit 29d119d into apache:master Mar 12, 2026
3 checks passed
@francescomari francescomari deleted the fix/jmx-mbean-leak-on-restart branch March 12, 2026 11:06
@francescomari francescomari changed the title Fix JMX MBean leak during Jetty restart cycle FELIX-6824 - Fix JMX MBean leak during Jetty restart cycle Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants