FELIX-6824 - Fix JMX MBean leak during Jetty restart cycle#482
Merged
paulrutter merged 1 commit intoapache:masterfrom Mar 12, 2026
Merged
Conversation
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.
paulrutter
reviewed
Mar 11, 2026
http/jetty/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
Show resolved
Hide resolved
paulrutter
reviewed
Mar 11, 2026
http/jetty12/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java
Show resolved
Hide resolved
paulrutter
approved these changes
Mar 11, 2026
Contributor
paulrutter
left a comment
There was a problem hiding this comment.
Approved, two comments un the PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
stopJetty()runs during a configuration-triggered restart, Jetty's JMX MBeans are not unregistered before theServeris stopped. On the subsequentstartJetty(), the newServercreates a newMBeanServerTrackerwhich tries to registerorg.eclipse.jetty.server:type=server,id=0— but the old registration still exists, causing anInstanceAlreadyExistsException.Root cause
Two issues:
JettyService.stopJetty()closes theMBeanServerTrackerafterserver.stop(). By the time the tracker is closed, the server's component tree has already been torn down, soMBeanContainercan no longer walk the tree to unregister its MBeans. They remain in the platformMBeanServeras stale entries.MBeanServerTracker.removedService()removes theMBeanContaineras an event listener and callssuper.removedService(), but never callsMBeanContainer.destroy(). Withoutdestroy(), the container does not unregister the MBeans it previously registered.Changes
JettyService.stopJetty()(both jetty and jetty12): movembeanServerTracker.close()beforeserver.stop()so the tracker is closed while the server's component tree is still intact and MBeans can be properly unregisteredMBeanServerTracker.removedService()(both jetty and jetty12): callservice.destroy()before removing the event listener, soMBeanContainerunregisters all MBeans it owns