Right way to shutdown in case of error

Michael McGrady mmcgrady at topiatechnology.com
Sun Sep 13 22:56:11 EDT 2009


I had this same problem and reason was that I unintentionally did not  
shut all channels.  I started using the ChannelGroup as indicated in  
the relevant javadocs and things are now working perfectly.

Mike

On Sep 13, 2009, at 12:01 PM, float_dublin wrote:

>
> Hello,
> If i try to shutdown netty in exceptionCaught method it hangs forever,
> searching this mail list shows i should do it in separate thread, is  
> it the
> only right way to close and release resources?
>
> Code snippet to reproduce Connection Refused hang:
>
> public class ClientTest {
>
>    @ChannelPipelineCoverage("all")
>    private class Client extends SimpleChannelHandler {
>
>        @Override
>        public void exceptionCaught(ChannelHandlerContext ctx, final
> ExceptionEvent e) throws Exception {
>            e.getCause().printStackTrace();
> //            new Thread() {
> //
> //                @Override
> //                public void run() {
>                    e.getChannel().close().awaitUninterruptibly();
>                    cb.releaseExternalResources();
> //                }
> //            }.start();
>        }
>    }
>    ClientBootstrap cb = new ClientBootstrap(new
> NioClientSocketChannelFactory(
>            Executors.newCachedThreadPool(),
> Executors.newCachedThreadPool()));
>
>    private void initClient() {
>        cb.setOption("tcpNoDelay", true);
>        cb.setOption("keepAlive", true);
>
>        final ChannelPipeline pipeline = cb.getPipeline();
>        pipeline.addLast("handler", new Client());
>
>        cb.connect(new InetSocketAddress("localhost", 20001)); //  
> Assuming
> nobody is home
>    }
>
>    public static void main(String[] args) {
>        new ClientTest().initClient();
>    }
> }
> -- 
> View this message in context: http://n2.nabble.com/Right-way-to-shutdown-in-case-of-error-tp3637599p3637599.html
> Sent from the Netty User Group mailing list archive at Nabble.com.
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users

Mike McGrady
Principal Investigator AF081-028 AFRL SBIR
Senior Engineer
Topia Technology, Inc
1.253.720.3365
mmcgrady at topiatechnology.com









More information about the netty-users mailing list