You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "francescomari (via GitHub)" <gi...@apache.org> on 2026/03/11 12:16:54 UTC
[PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
francescomari opened a new pull request, #482:
URL: https://github.com/apache/felix-dev/pull/482
## 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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
Posted by "francescomari (via GitHub)" <gi...@apache.org>.
francescomari commented on code in PR #482:
URL: https://github.com/apache/felix-dev/pull/482#discussion_r2923437230
##########
http/jetty/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java:
##########
@@ -59,6 +59,7 @@ public void removedService(ServiceReference<MBeanServer> reference, MBeanContain
{
if ( service != null )
{
+ service.destroy();
Review Comment:
It doesn't look like. That method clears some data structures and deregisters every registered MBeans. The only code that can throw is called indirectly in `org.eclipse.jetty.jmx.MBeanContainer#unregister`, but that method already has proper exception handling.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
Posted by "francescomari (via GitHub)" <gi...@apache.org>.
francescomari commented on code in PR #482:
URL: https://github.com/apache/felix-dev/pull/482#discussion_r2923439304
##########
http/jetty12/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java:
##########
@@ -59,6 +59,7 @@ public void removedService(ServiceReference<MBeanServer> reference, MBeanContain
{
if ( service != null )
{
+ service.destroy();
Review Comment:
Same as [above](https://github.com/apache/felix-dev/pull/482#discussion_r2923437230).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
Posted by "paulrutter (via GitHub)" <gi...@apache.org>.
paulrutter commented on code in PR #482:
URL: https://github.com/apache/felix-dev/pull/482#discussion_r2920335246
##########
http/jetty12/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java:
##########
@@ -59,6 +59,7 @@ public void removedService(ServiceReference<MBeanServer> reference, MBeanContain
{
if ( service != null )
{
+ service.destroy();
Review Comment:
Same as above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
Posted by "paulrutter (via GitHub)" <gi...@apache.org>.
paulrutter merged PR #482:
URL: https://github.com/apache/felix-dev/pull/482
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix JMX MBean leak during Jetty restart cycle [felix-dev]
Posted by "paulrutter (via GitHub)" <gi...@apache.org>.
paulrutter commented on code in PR #482:
URL: https://github.com/apache/felix-dev/pull/482#discussion_r2920333500
##########
http/jetty/src/main/java/org/apache/felix/http/jetty/internal/MBeanServerTracker.java:
##########
@@ -59,6 +59,7 @@ public void removedService(ServiceReference<MBeanServer> reference, MBeanContain
{
if ( service != null )
{
+ service.destroy();
Review Comment:
Could this throw? Do we need a try catch?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@felix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org