Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 311554

Summary: ShutdownThread.deregister(this) in Server.doStop causes IllegalStateException at shutdown
Product: [RT] Jetty Reporter: Eirik Bjørsnøs <eirbjo>
Component: serverAssignee: Greg Wilkins <gregw>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eirbjo, jetty-inbox
Version: unspecified   
Target Milestone: 7.0.2.RC0   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:
Bug Depends on:    
Bug Blocks: 312526    

Description Eirik Bjørsnøs CLA 2010-05-04 10:09:55 EDT
Build Identifier: 


Problem:

I have my own shutdown hook registered that calls Server.stop() Server.doStop calls ShutDownThread.deregister which ends up calling Runtime.addShutdownHook in ShutdownThread's constructor.

Runtime.addShutdownHook then causes an IllegalStateException because shutdown is already in progress:

java.lang.IllegalStateException: Shutdown in progress
        at java.lang.Shutdown.add(Shutdown.java:81)
        at java.lang.Runtime.addShutdownHook(Runtime.java:190)
        at org.eclipse.jetty.util.thread.ShutdownThread.<init>(ShutdownThread.java:48)
        at org.eclipse.jetty.util.thread.ShutdownThread.<clinit>(ShutdownThread.java:36)
        at org.eclipse.jetty.server.Server.doStop(Server.java:315)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:80)


Solution:

ShutDownThread.deregister in Server.doStop should probably be protected by an if(getStopAtShutdown()) as is ShutdownThread.register in doStart().


Reproducible: Always

Steps to Reproduce:
1. Create and register a custom shutdown thread that will call Server.stop
2. Start server
3.  Stop server
4. Observe stacktrace.
Comment 1 Greg Wilkins CLA 2010-05-05 09:07:18 EDT
Fixed thanks!

r1772