Can't close a Netty Client
Francis Barber
fedora at barber-family.id.au
Tue Jul 26 09:37:54 EDT 2011
Sounds a similar to a problem I described here:
https://issues.jboss.org/browse/NETTY-412
I'm working on fixing this bug.
On 26/07/2011 3:11 AM, Jonathan Arnold wrote:
> I figured out my problem, perhaps it will help with yours. My problem
> was a typical problem it seems - an exception was being thrown that was
> getting caught, ignored, and then retried. This meant a worker thread
> (in this case, in efflux, the RTP library), never terminated.
>
> I figured this out by running my app in the debugger and then when it
> hung, to pause it and look at all the threads. Well, there were only 2
> in my case - the main one and the rogue worker thread. It was throwing
> an exception at a very low level, but that exception was getting
> caught at a slightly higher level and being ignored. Ad infinitum.
>
> On Wed, 20 Jul 2011 01:42:51 -0700 (PDT)
> "B.L. Zeebub" <roger.varley at googlemail.com> wrote:
>
>> Hi
>>
>> Below is the code which starts my NettyClient. The class
>> NettyClientService is created and started by an external application.
>> When the external application terminates, it calls
>> NettyClientService.shutdown() which hangs.
>>
>> As the code is written, it's hanging on the
>> channel.close().awaitUninterruptibly(). If I change that to simple
>> channel.close(), then the class hangs on
>> bootstrap.releaseExternalResources();
>>
>> Any suggestions on what's wrong, or on how I can further diagnose the
>> problem?
>>
>> Regards
>> Roger
>>
>>
>>
>> package com.blackbox.x.comms.client;
>>
>> import java.net.InetSocketAddress;
>> import java.util.concurrent.Executors;
>>
>> import org.apache.log4j.Logger;
>> import org.jboss.netty.bootstrap.ClientBootstrap;
>> import org.jboss.netty.channel.Channel;
>> import org.jboss.netty.channel.ChannelFuture;
>> import
>> org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
>> import org.jboss.netty.util.HashedWheelTimer; import
>> org.jboss.netty.util.Timer;
>>
>> import com.blackbox.x.comms.common.CommandExecutor;
>>
>>
>>
>> public class NettyClientService implements Runnable {
>>
>> private static final Logger logger = Logger
>> .getLogger(NettyClientService.class.getName());
>>
>> private Channel channel;
>>
>> private String host;
>>
>> private CommandExecutor executor;
>>
>> private ClientBootstrap bootstrap;
>>
>> public NettyClientService(String host, CommandExecutor
>> executor) { this.host = host;
>> this.executor = executor;
>> }
>>
>> public void run() {
>>
>> logger.info("Trying to connect to host " + host);
>>
>> bootstrap = new ClientBootstrap(new
>> NioClientSocketChannelFactory(Executors
>> .newCachedThreadPool(),Executors.newCachedThreadPool()));
>>
>> // Set up the event pipeline factory.
>> Timer timer = new HashedWheelTimer();
>> bootstrap.setPipelineFactory(new
>> ClientPipelineFactory(executor,timer));
>> bootstrap.setOption("keepAlive", true);
>> // Make a new connection.
>> ChannelFuture future = bootstrap.connect(new
>> InetSocketAddress( host, 5956));
>>
>> channel = future.awaitUninterruptibly().getChannel();
>> if (!channel.isConnected()) {
>>
>> logger.error("Failed to connect to " + host);
>> executor.close();
>> bootstrap.releaseExternalResources();
>> return;
>> }
>>
>> logger.info("Connected to " + host);
>> }
>>
>> public void shutdown() {
>>
>>
>> if (channel != null) {
>> channel.close().awaitUninterruptibly();
>> }
>> if (bootstrap != null) {
>> bootstrap.releaseExternalResources();
>> }
>>
>> }
>>
>>
>> }
>>
>> --
>> View this message in context:
>> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Can-t-close-a-Netty-Client-tp6601815p6601815.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
>
>
More information about the netty-users
mailing list