当把项目Nginx作负载均衡时,有些时间较长的请求,Tomcat就报如下错误:
org.apache.catalina.connector.ClientAbortException: java.io.IOException: 断开的管道 at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer. at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk. at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer. at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer. at org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream. at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder. at sun.nio.cs.StreamEncoder.flush(StreamEncoder. at at org.springframework.util.StreamUtils.copy(StreamUtils. at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter. at org.springframework.http.converter.StringHttpMessageConverter.writeInternal(StringHttpMessageConverter. at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter. at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor. at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor. at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor. at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite. at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter. at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter. at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter. at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet. at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet. at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet. at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet. at at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet. at at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.jasig.cas.client.util.AssertionThreadLocalFilter.doFilter(AssertionThreadLocalFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at com.bfd.filter.CASFilter.doFilter(CASFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at com.bfd.filter.CrossDomainFilter.doFilter(CrossDomainFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter. at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter. at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain. at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain. at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve. at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve. at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase. at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve. at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve. at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve. at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter. at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor. at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint. at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint. at at at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread. at Caused by: java.io.IOException: 断开的管道 at sun.nio.ch.FileDispatcherImpl.write0(Native Method) at sun.nio.ch.SocketDispatcher.write(SocketDispatcher. at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil. at sun.nio.ch.IOUtil.write(IOUtil. at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl. at org.apache.tomcat.util.net.NioChannel.write(NioChannel. at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector. at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool. at org.apache.coyote.http11.InternalNioOutputBuffer.writeToSocket(InternalNioOutputBuffer. at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer. at org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer. at org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer. at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter. at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer. at org.apache.coyote.Response.doWrite(Response. at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer. ... 73 mo
如上报错原因就是连接断开了。 具体错在哪里呐: 最后发现问题在Nginx,发现Nginx的连接超时时间设计的太短了,当服务器处理时间比较长时,等返回结果时,Nginx端已经超时断链了,Tomcat就报错了。解决方法就是把Nginx时间调大一点,就行。