I am trying to shut down a Netty server with open connections to it, and it just freezes. That's what I'm doing.
- Start the server on one computer and the client on another.
- Send a message from the client to the server to which I receive a response.
- Disconnect a server using Ctrl-C
I registered a disconnect hook on a server that closes ChannelGroup and calls releaseExternalResources on ServerBootstrap (or actually I use the protobuf-pro-duplex library DuplexTcpServerBootstrap, which does just that). In any case, when turned off, the shutdown hook is called properly, but it never returns. When I take the thread of discarding what is happening, I see two interesting stacks:
java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000006b0890950> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082) at java.util.concurrent.ThreadPoolExecutor.awaitTermination(ThreadPoolExecutor.java:1433) at org.jboss.netty.util.internal.ExecutorUtil.terminate(ExecutorUtil.java:103) at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.releaseExternalResources(AbstractNioWorkerPool.java:80) at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.releaseExternalResources(NioServerSocketChannelFactory.java:162) at org.jboss.netty.bootstrap.Bootstrap.releaseExternalResources(Bootstrap.java:319) at com.googlecode.protobuf.pro.duplex.server.DuplexTcpServerBootstrap.releaseExternalResources(DuplexTcpServerBootstrap.java:132) at com.xxx.yyy.node.NodeServer$2.run(NodeServer.java:104) at java.lang.Thread.run(Thread.java:722)
So this is a disconnect stream that never returns. And below is another thread that seems to be waiting on the channel:
java.lang.Thread.State: RUNNABLE at sun.nio.ch.EPollArrayWrapper.interrupt(Native Method) at sun.nio.ch.EPollArrayWrapper.interrupt(EPollArrayWrapper.java:274) at sun.nio.ch.EPollSelectorImpl.wakeup(EPollSelectorImpl.java:193) - locked <0x00000006b0896660> (a java.lang.Object) at java.nio.channels.spi.AbstractSelector$1.interrupt(AbstractSelector.java:210) at java.nio.channels.spi.AbstractSelector.begin(AbstractSelector.java:216) at sun.nio.ch.EPollSelectorImpl.doSelect(EPollSelectorImpl.java:80) at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:87) - locked <0x00000006b08964a8> (a sun.nio.ch.Util$2) - locked <0x00000006b0896498> (a java.util.Collections$UnmodifiableSet) - locked <0x00000006b0890d20> (a sun.nio.ch.EPollSelectorImpl) at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:98) at org.jboss.netty.channel.socket.nio.SelectorUtil.select(SelectorUtil.java:52) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:208) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:38) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)
I am using Netty 3.4.6.Final with Java 7.04 for Linux. Thanks!
Br, Frank.
source share