【发布时间】:2012-12-03 13:39:48
【问题描述】:
我正在运行一个基于 netty (3.2.5.Final.jar) 的(自制)中间件“服务连接器(SC)”,它基本上是 http 流量的代理。任何传入的请求都会被转发到一个远程节点,最后是一个 apache。
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
ChannelBuffer msg = (ChannelBuffer) event.getMessage();
outboundChannel.write(msg);
}
我通过浏览器向 SC 发送请求,例如:“http://localhost:9104/testHtml.htm”
它通常可以完美运行!有时浏览器会永远循环。不同的模式(不同的文件、大小、时间)
查看 netty 日志:
2012-11-28 17:54:12.326+0100 [New I/O server boss #9 ([id: 0x015bdc50, /10.43.18.160:9104])] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] OPEN
2012-11-28 17:54:12.342+0100 [New I/O server boss #9 ([id: 0x015bdc50, /10.43.18.160:9104])] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] BOUND: /10.43.18.160:9104
2012-11-28 17:54:12.357+0100 [New I/O server boss #9 ([id: 0x015bdc50, /10.43.18.160:9104])] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] CONNECTED: /10.43.18.160:52499
2012-11-28 17:54:12.342+0100 [SC_WORKER thread-13] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] CHANGE_INTEREST: 0
2012-11-28 17:54:12.420+0100 [New I/O server worker #9-20] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] RECEIVED: BigEndianHeapChannelBuffer(ridx=0, widx=501, cap=501) - (HEXDUMP: ....)
2012-11-28 17:54:12.435+0100 [SC_WORKER thread-13] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:39) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] INTEREST_CHANGED
2012-11-28 17:54:12.451+0100 [SC_WORKER thread-11] DEBUG (org.jboss.netty.handler.logging.LoggingHandler:43) - [id: 0x00f6fd54, /10.43.18.160:52499 => /10.43.18.160:9104] EXCEPTION: java.lang.NullPointerException
java.lang.NullPointerException
at org.serviceconnector.net.res.netty.tcp.proxy.NettyTcpProxyResponderRequestHandler.messageReceived(NettyTcpProxyResponderRequestHandler.java:127)
at org.jboss.netty.handler.execution.ChannelEventRunnable.run(ChannelEventRunnable.java:69)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
在调试模式下,我可以看到 msg 和 outboundChannel 都为空:/ 如果我将代码更改为以下代码,它可以工作。
如果出现错误,只需重新编写消息
try{
outboundChannel.write(msg);
} catch(Throwable t) {
outboundChannel.write(msg);
}
或者放慢线程
Thread.sleep(200);
outboundChannel.write(msg);
我想我正面临着比赛条件。它只发生在慢速机器上 当然它很难复制,unfor。我无法提供示例。
我用相同的行为尝试了 netty 3.5.10.Final。有人观察到类似的行为吗? 谢谢!
【问题讨论】:
-
请告诉我你的完整处理程序..
标签: netty