I am running a (selfmade) middleware “Service Connector (SC)” basing on netty (3.2.5.Final.jar) which basically is a proxy for http traffic. Any incoming request is forwarded to a remote node, an apache at the end.
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
ChannelBuffer msg = (ChannelBuffer) event.getMessage();
outboundChannel.write(msg);
}
I am sending a request over the browser to the SC for example: “http://localhost:9104/testHtml.htm”
it usually works perfect! Occasionally the browser loops forever. Different patterns (different files, sizes, times)
Looking into the netty log:
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)
In debug mode i can see either msg nor outboundChannel is null :/
if i change to code to the following it works.
just write the message again in case of error
try{
outboundChannel.write(msg);
} catch(Throwable t) {
outboundChannel.write(msg);
}
or slow down the thread
Thread.sleep(200);
outboundChannel.write(msg);
guess i am facing a race condition. it only happens on slow machines
of course its hard to reproduce, unfor. i am not able to provide an example.
i tried netty 3.5.10.Final with the same behavior. any one observing similar behaviour?
thx!
outboundChannelcan only benullifmessageReceivedis invoked beforechannelOpen. Usually, it never happens, but it can happen if your pipeline has anExecutionHandlerbefore your handler and you are using an unordered executor service. If so, please use anExecutorServicesuch asOrderedMemoryAwareThreadPoolExecutor.