exceptionCaught错误处理回写响应导致异常和无限调用exceptionCaught [英] exceptionCaught error handling write back response causes exception and infiniteLoop of calling exceptionCaught
问题描述
这是我的问题:在我的Handler中扩展了SimpleChannelUpstreamHandler,当在堆栈中的任何地方抛出异常时,将会触发exceptionCaught。那很好。不好的是,当我尝试用适当的HTTP代码和响应向客户端写出响应时,写入会导致异常,然后程序进入一个无限循环,再次调用exceptionCaught。
这必须是一个常用的任务。如何正确执行?
@Override
public void exceptionCaught(ChannelHandlerContext ctx,ExceptionEvent event)
抛出异常{
try {
logger.error(处理调用中的错误,event.getCause());
HttpResponse httpResponse = buildHttpResponseObject(UNAUTHORIZED,new StringBuilder(Test),false,null);
//写入响应。
//由于某种原因调用下一行会导致一个无限循环的exceptionCaught,即使
// catch在下面。不知道为什么还在调查在此期间,我们没有自定义错误代码响应。
ChannelFuture future = event.getChannel()。write(httpResponse);
//写入操作完成后关闭连接,即使它是保持活动的。
future.addListener(ChannelFutureListener.CLOSE);
}
catch(异常t){
logger.error(无法自定义错误响应,t);
event.getChannel()。close();
}
}
以下是例外: p>
38161 [新的I / O服务器工作人员#1-1]错误nettytests.http.snoop.HttpSnoopServerHandler - 处理调用时出错:
javax.net.ssl.SSLHandshakeException:null cert chain
at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1364)
at sun.security.ssl.SSLEngineImpl.checkTaskThrown( SSLEngineImpl.java:513)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:790)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
在org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:931)
在org .jboss.netty.handler.ssl.SslHandler.decode(SslHandler.java:649)
在org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:288)
在org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.j ava:207)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
在org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
在org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker。 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java)中的
1110)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
引起:javax.net.ssl.SSLHandshakeException:null cert chain
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl。 java:1639)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:278)
at sun.security.ssl.Handshaker.fatalSE( Handshaker.java:266)
at sun.security.ssl.ServerHandshaker.clientCertificate(ServerHandshaker.java:1627)
at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:176)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker $ 1.run(Handshaker.java:808)
at sun.security。 ssl.Handshaker $ 1.run(Handshaker.java:806)
at java.security.AccessController.doPrivileged(Native Method)
at sun.security.ssl.Handshaker $ DelegatedTask.run(Handshaker.java: 1301)
在org.jboss.netty.handler.ssl.SslHandler $ 3.run(SslHandler.java:1060)
在org.jboss.netty.handler.ssl.ImmediateExecutor.execute(ImmediateExecutor.java :31)
在org.jboss.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1057)
在org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java :947)
... 11更多
38177 [新的I / O服务器工作人员#1-1]错误nettytests.http.snoop.HttpSnoopS erverHandler - 处理调用时出错:
java.lang.IllegalStateException:不能发送比请求更多的响应
在org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
在nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
在nettytests.logger.RequestAuditLogger .handleUpstream(RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl .SslHandler.exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCau ght(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels。 java:255)
在org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
在org.jboss.netty.channel.socket.nio.NioWorker。 processSelectedKeys(NioWorker.java:274)
在org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
在java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1110)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
38177 [新的I / O服务器工作人员#1-1]错误nettytests.http.snoop.HttpSnoopServerHandler - 处理调用时出错:
java.lang.IllegalStateException:无法发送比请求更多的响应
org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104 )
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
在nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
在nettytests.logger。 RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler。 ssl.SslHandler.exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink。 exceptionCaught(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels。 java:572)
在org.jboss.netty.channel.AbstractChannel.wr ite(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
在org.jboss .netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
在org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
在org.jboss.netty.channel.socket。 nio.NioWorker.run(NioWorker.java:194)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent.ThreadPoolExecutor $ Worker.run( ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
38224 [新的I / O服务器工作人员#1-1]错误nettytests.http.snoop.HttpSnoopServerHandler - 处理调用时出错:
java.lang.IllegalStateException:不能发送比请求更多的响应
在org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger。 handleUpstream(RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java: 554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org .bbb.net.net。 (RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler .exceptionCaught(SslHandler.java:554 )
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org。 (bt) RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler。 exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink。 java:47)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
在org.jboss .netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
在org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
在org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java .util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
38255 [新的I / O服务器工作#1 -1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - 处理调用中的错误:
java.lang.IllegalStateException:不能在org.jboss.netty.handler.codec.http发送比请求
更多的响应。 HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
在org.jboss.netty.channel.Chan nels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty.channel.AbstractChannel.write( AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
(org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught $ b在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org .jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty .channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
在nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
在org.jboss.netty.handler.codec。 replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel。 Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org.jboss.netty.channel.Channels.write( Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java: 245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
a t org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org .jboss.netty.channel.Channels.write(Channels.java:605)
在org.jboss.netty.channel.Channels.write(Channels.java:572)
在org.jboss.netty 。netcode.bat :32)
在org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
在org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler .java:554)
在org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
在org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
在org.jboss .netty.channel.Channels.fireMessageReceived(Channels.java:268)
在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
在org.jboss.netty.channel .socket.nio.NioWorker.read(NioWorker.java:343)
在org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
在org.jboss .netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util.concurrent .ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
在java.lang.Thread.run(Thread.java:722)
...重复广告无限。
无限循环是坏的..我注意到,你在finally块中调用Channel.close()。大多数情况下,您可以在频道中写入内容。您应该使用
future.addListener(ChannelFutureListener.CLOSE);
关闭频道后写的东西这甚至应该被调用一个异常
I'm trying to genericize my error handling for HTTP requests, and always respond with an actual error HTTP code and relevant message.
Here is my issue: in my Handler which extends SimpleChannelUpstreamHandler, exceptionCaught is fired when an exception is thrown anywhere in the stack. That's good. The bad part is that when I try to write out a response to the client with an appropriate HTTP code and response, the write causes an exception, and then the program goes into an infinite loop with calling exceptionCaught over and over again.
This has to be a commonly done task. How can I do it correctly?
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event)
throws Exception {
try{
logger.error("Error in handling call: ", event.getCause());
HttpResponse httpResponse = buildHttpResponseObject(UNAUTHORIZED, new StringBuilder("Test"), false, null);
// Write the response.
// for some reason calling this next line causes an infinite loop of exceptionCaught, even with the
// catch below. No idea why. Still investigating. In the meantime, we don't have custom error code responses.
ChannelFuture future = event.getChannel().write(httpResponse);
// Close the connection after the write operation is done, even if it's a keep-alive.
future.addListener(ChannelFutureListener.CLOSE);
}
catch(Exception t){
logger.error("Unable to customize error response. ", t);
event.getChannel().close();
}
}
Here are the exceptions:
38161 [New I/O server worker #1-1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - Error in handling call:
javax.net.ssl.SSLHandshakeException: null cert chain
at sun.security.ssl.Handshaker.checkThrown(Handshaker.java:1364)
at sun.security.ssl.SSLEngineImpl.checkTaskThrown(SSLEngineImpl.java:513)
at sun.security.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:790)
at sun.security.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:758)
at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:624)
at org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:931)
at org.jboss.netty.handler.ssl.SslHandler.decode(SslHandler.java:649)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:288)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:207)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.net.ssl.SSLHandshakeException: null cert chain
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLEngineImpl.fatal(SSLEngineImpl.java:1639)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:278)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:266)
at sun.security.ssl.ServerHandshaker.clientCertificate(ServerHandshaker.java:1627)
at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:176)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:868)
at sun.security.ssl.Handshaker$1.run(Handshaker.java:808)
at sun.security.ssl.Handshaker$1.run(Handshaker.java:806)
at java.security.AccessController.doPrivileged(Native Method)
at sun.security.ssl.Handshaker$DelegatedTask.run(Handshaker.java:1301)
at org.jboss.netty.handler.ssl.SslHandler$3.run(SslHandler.java:1060)
at org.jboss.netty.handler.ssl.ImmediateExecutor.execute(ImmediateExecutor.java:31)
at org.jboss.netty.handler.ssl.SslHandler.runDelegatedTasks(SslHandler.java:1057)
at org.jboss.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:947)
... 11 more
38177 [New I/O server worker #1-1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - Error in handling call:
java.lang.IllegalStateException: cannot send more responses than requests
at org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
38177 [New I/O server worker #1-1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - Error in handling call:
java.lang.IllegalStateException: cannot send more responses than requests
at org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
38224 [New I/O server worker #1-1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - Error in handling call:
java.lang.IllegalStateException: cannot send more responses than requests
at org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
38255 [New I/O server worker #1-1] ERROR nettytests.http.snoop.HttpSnoopServerHandler - Error in handling call:
java.lang.IllegalStateException: cannot send more responses than requests
at org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:104)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.write(Channels.java:605)
at org.jboss.netty.channel.Channels.write(Channels.java:572)
at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:245)
at nettytests.http.snoop.HttpSnoopServerHandler.exceptionCaught(HttpSnoopServerHandler.java:201)
at nettytests.logger.RequestAuditLogger.handleUpstream(RequestAuditLogger.java:32)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.exceptionCaught(ReplayingDecoder.java:456)
at org.jboss.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:554)
at org.jboss.netty.channel.Channels.fireExceptionCaught(Channels.java:426)
at org.jboss.netty.channel.AbstractChannelSink.exceptionCaught(AbstractChannelSink.java:47)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:343)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:274)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
... repeat ad infinitum.
Infinity loop is bad.. what I noticed is that you call Channel.close() in the finally block. This will most times happen before you can write something to the Channel. You should use the
future.addListener(ChannelFutureListener.CLOSE);
To Close the channel after you have written something. This should even get called on an Exception
这篇关于exceptionCaught错误处理回写响应导致异常和无限调用exceptionCaught的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!