If an exception is raised from the undertow.start() method, should I attempt to stop the deployments and server in order to clean up, or just leave them be? I've run into a scenario where if I try to start up a server on a port which is already bound, I get the exception thrown
Caused by: java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.ServerSocketChannelImpl.netBind(ServerSocketChannelImpl.java:337)
at java.base/sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:294)
at java.base/sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:89)
at org.xnio.nio.NioXnioWorker.createTcpConnectionServer(NioXnioWorker.java:178)
at org.xnio.XnioWorker.createStreamConnectionServer(XnioWorker.java:310)
at io.undertow.Undertow.start(Undertow.java:174)
which makes perfect sense, but when I attempt to clean up by stopping everything, I get a hung thread which looks like this:
"Thread-2" #37 prio=5 os_prio=0 cpu=15.62ms elapsed=4564.89s tid=0x000002ca48c52630 nid=0x12814 waiting on condition [0x000000eadb3ff000]
java.lang.Thread.State: WAITING (parking)
at jdk.internal.misc.Unsafe.park(java...@17.0.9/Native Method)
at java.util.concurrent.locks.LockSupport.park(java...@17.0.9/LockSupport.java:341)
at org.xnio.nio.WorkerThread$SelectNowTask.doWait(WorkerThread.java:915)
at org.xnio.nio.WorkerThread.cancelKey(WorkerThread.java:793)
at org.xnio.nio.NioHandle.cancelKey(NioHandle.java:91)
at org.xnio.nio.NioTcpServer.close(NioTcpServer.java:261)
at org.xnio.nio.QueuedNioTcpServer2.close(QueuedNioTcpServer2.java:126)
at org.xnio.IoUtils.safeClose(IoUtils.java:152)
at io.undertow.Undertow.stop(Undertow.java:262)
This thread never finishing, leaving my server hung. It would appear that the port in use error left Undertow in an invalid state, but I would have expecfted the stop() method to be safe to call. In the event of an exception thrown from the start(), should I not stop anything and just assume Undertow has cleaned up what it can?