netty客户端挂起连接



我正在使用一个名为Cloudhopper的SMPP库,该库使用底层netty 3.9.9连接到SMPP服务器。当连接断开时,我会尝试重新连接。在大多数情况下,这是有效的,但有时重新连接会挂起。有问题的代码是(或请参阅https://github.com/twitter/cloudhopper-smpp/blob/master/src/main/java/com/cloudhopper/smpp/impl/DefaultSmppClient.java#L286):

// a socket address used to "bind" to the remote system
InetSocketAddress socketAddr = new InetSocketAddress(host, port);
// set the timeout
this.clientBootstrap.setOption("connectTimeoutMillis", connectTimeoutMillis);
// attempt to connect to the remote system
ChannelFuture connectFuture = this.clientBootstrap.connect(socketAddr);
connectFuture.awaitUninterruptibly();

clientBootstrap每次都会被重复使用。线程转储如下所示:

"Sender Heartbeat 1" prio=10 tid=0x00007f0b50feb800 nid=0x7fa in Object.wait() [0x00007f0b849e2000]
   java.lang.Thread.State: WAITING (on object monitor)
    at java.lang.Object.wait(Native Method)
    - waiting on <0x00000000caa999b0> (a org.jboss.netty.channel.DefaultChannelFuture)
    at java.lang.Object.wait(Object.java:503)
    at org.jboss.netty.channel.DefaultChannelFuture.awaitUninterruptibly(DefaultChannelFuture.java:259)
    - locked <0x00000000caa999b0> (a org.jboss.netty.channel.DefaultChannelFuture)
    at com.cloudhopper.smpp.impl.DefaultSmppClient.createConnectedChannel(DefaultSmppClient.java:286)
    at com.cloudhopper.smpp.impl.DefaultSmppClient.doOpen(DefaultSmppClient.java:224)
    at com.cloudhopper.smpp.impl.DefaultSmppClient.bind(DefaultSmppClient.java:193)

有人没有向DefaultChannelFuture发送通知。有人知道如何进一步调查吗?是什么原因导致netty没有发送通知?到目前为止,我无法在本地复制它,所以我无法调试它

我在cloudhopper库提交了一份错误报告,但我希望我能发现更多,甚至可能贡献一个修复程序。

干杯如文

干杯如文

我实际上用以下解决方法解决了它(以防有人遇到同样的问题):

    if (!connectFuture.await(connectTimeoutMillis + 1000)) {
        logger.error("connectFuture did not finish in expected time! Try to cancel the connectFuture");
        boolean isCanceled = connectFuture.cancel();
        logger.error("connectFuture: isCanceled {} isDone {} isSuccess {}", isCanceled, connectFuture.isDone(), connectFuture.isSuccess());
        throw new SmppChannelConnectTimeoutException("Could not connect to the server within timeout");
    }

考虑到Netty版本(3.9.6.Final)非常旧,我没有在Netty项目中提交错误。但我在cloudhopper项目中添加了一个PR。

最新更新