Open krasa opened 9 years ago
Sometimes I think Netty4 should have taken a new project name due to its massive backwards incompatibility. Have you dug into what you think the underlying problem is?
It looks like a netty bug to me. I will dig deeper if you do not have a time.
testcase:
public class Netty4Deadlock {
private static final Logger logger = LoggerFactory.getLogger(Netty4Deadlock.class);
public static void main(String[] args) throws UnrecoverablePduException, SmppChannelException, InterruptedException, SmppTimeoutException {
DefaultChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
Bootstrap clientBootstrap = new Bootstrap();
NioEventLoopGroup workerGroup = new NioEventLoopGroup();
clientBootstrap.group(workerGroup);
clientBootstrap.channel(NioSocketChannel.class);
clientBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000);
clientBootstrap.handler(new LoggingHandler());
ChannelFuture connectFuture = clientBootstrap.connect(new InetSocketAddress("localhost", 5000));
destroy(channels, workerGroup);
logger.info("deadlock here:");
connectFuture.awaitUninterruptibly();
logger.info("done");
}
private static void destroy(DefaultChannelGroup channels, NioEventLoopGroup workerGroup) {
logger.info("destroy");
channels.close().awaitUninterruptibly();
workerGroup.shutdownGracefully();
try {
// Wait until all threads are terminated.
workerGroup.terminationFuture().sync();
} catch (InterruptedException e) {
logger.warn("Thread interrupted closing executors.", e);
}
}
}
I was building a new performance test https://github.com/krasa/cloudhopper-smpp/commit/b458153ad8061968b777166999b2d87cb02d38b7 and when I call DefaultSmppClient#destroy while other threads are binding, then it will never shutdown. (reproducible in majority of runs, when the server is not running)
Netty 3 did not have this problem ( https://github.com/krasa/cloudhopper-smpp/commit/fd78835d74992e476b5a584f5b8bd65cc4947dd8 ).