javaee / grizzly

Writing scalable server applications in the Java™ programming language has always been difficult. Before the advent of the Java New I/O API (NIO), thread management issues made it impossible for a server to scale to thousands of users. The Grizzly NIO framework has been designed to help developers to take advantage of the Java™ NIO API.
https://javaee.github.io/grizzly/
Other
222 stars 60 forks source link

server#shutdown does not properly deallocate JMX mbeans #1835

Closed glassfishrobot closed 8 years ago

glassfishrobot commented 8 years ago

Calling shutdownNow causes proper deregistration of JMX beans. Calling just "shutDown" will not deregister the beans, so if you try to restart the same application within the same JVM you will get an error.

Affected Versions

[2.3.24]

glassfishrobot commented 8 years ago

Reported by kristian.rosenvold

glassfishrobot commented 8 years ago

kristian.rosenvold said: The error message upon second registration is:

ava.lang.IllegalArgumentException: WARNING: GMBAL00609: Object org.glassfish.grizzly.http.server.jmx.HttpServer@3e53fbde is already registered as MBeanImpl[type=HttpServer,name=XXZZ,oname=org.glassfish.grizzly:pp=/gmbal-root,type=HttpServer,name=XXZZ]

Stack trace for failing second registration is:

at org.glassfish.gmbal.impl.MBeanTree.register(MBeanTree.java:366) at org.glassfish.gmbal.impl.ManagedObjectManagerImpl.register(ManagedObjectManagerImpl.java:707) at org.glassfish.gmbal.impl.ManagedObjectManagerImpl.registerAtRoot(ManagedObjectManagerImpl.java:721) at org.glassfish.grizzly.monitoring.jmx.DefaultJmxManager.registerAtRoot(DefaultJmxManager.java:79) at org.glassfish.grizzly.monitoring.jmx.DefaultJmxManager.registerAtRoot(DefaultJmxManager.java:53) at org.glassfish.grizzly.http.server.HttpServer.enableJMX(HttpServer.java:612) at org.glassfish.grizzly.http.server.HttpServer.start(HttpServer.java:272)

glassfishrobot commented 8 years ago

kristian.rosenvold said: Testcase to reproduce:

Ensure org.glassfish.grizzly.monitoring.jmx.DefaultJmxManager is on classpath:

@Test
    public void startTwice() throws IOException {
        HttpServer server = createServer();
        server.start();
        server.shutdown();

        HttpServer server2 = createServer();
        server2.start();
        server2.shutdown();
    }

    private HttpServer createServer() {
        HttpServer server2 = new HttpServer();
        ServerConfiguration serverConfiguration2 = server2.getServerConfiguration();
        serverConfiguration2.setName("fizzbuzz");
        serverConfiguration2.setJmxEnabled(true);
        return server2;
    }
glassfishrobot commented 8 years ago

@rlubke said: The root of the issue is that the logic assumes there will be listeners which will be shutdown and ultimately call shutdownNow() on the HttpServer instance. In this case, there are no listeners, so the JMX tear-down logic isn't invoked.

This is certainly an edge case, but I've added logic to deal with it. Tests are running now. If all goes well, will commit the changes.

glassfishrobot commented 8 years ago

@rlubke said: Changes applied:

2.3.x: b04f6572b80593b65eb241b6fa01c3902756a35e master: 765f6917e9ac24b4cb9e43a90f979dac53de57ba

glassfishrobot commented 7 years ago

This issue was imported from java.net JIRA GRIZZLY-1835

glassfishrobot commented 8 years ago

Marked as fixed on Tuesday, June 14th 2016, 10:17:58 pm