数百个CLOSE_WAIT连接正在吞噬我的ThreadPools

时间:2013-02-13 15:19:56

标签: java tcp jboss wait

我们有一个非常残酷的情况。我们在德国有一个网站,这是一个在线商店。我们每天多次在CLOSE_WAIT状态下拥有大量连接,这些状态在同一个ip中显示在netstat中。这是不同的IP,但它们都在中国。 我们还有中国客户。 检查访问日志,我们看到问题中来自ip的流量来自一个浏览器(useragent,会话ID),但它看起来不像真正的流量,例如连续请求/ 500次而不请求css ,js,背后的图像。 所以我们最终得到的就是在socketWrite0中有1000个线程,其中820将绑定到同一个ip:

"http--0.0.0.0-8443-1201" daemon prio=10 tid=0x00007f7435257800 nid=0x5361 runnable [0x00007f73e162a000]
   java.lang.Thread.State: RUNNABLE
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:724)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:449)
    at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)
    at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:748)
    at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126)
    at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:559)
    at org.apache.coyote.Response.doWrite(Response.java:594)
    at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:398)
    at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:449)
    at org.apache.catalina.connector.OutputBuffer.realWriteChars(OutputBuffer.java:473)
    at org.apache.tomcat.util.buf.CharChunk.flushBuffer(CharChunk.java:469)
    at org.apache.tomcat.util.buf.CharChunk.append(CharChunk.java:295)
    at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:505)
    at org.apache.catalina.connector.CoyoteWriter.write(CoyoteWriter.java:143)
    at org.apache.catalina.connector.CoyoteWriter.write(CoyoteWriter.java:152)
    at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:240)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488)
    at x.y.z.common.web.dispatch.StartPageDispatcherServlet.forward(StartPageDispatcherServlet.java:52)
    at x.y.z.common.web.dispatch.StartPageDispatcherServlet.service(StartPageDispatcherServlet.java:37)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at net.anotheria.moskito.web.MoskitoFilter.doFilter(MoskitoFilter.java:110)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at net.anotheria.moskito.web.MoskitoFilter.doFilter(MoskitoFilter.java:110)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at net.anotheria.moskito.web.filters.JourneyFilter.doFilter(JourneyFilter.java:84)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at net.anotheria.moskito.web.filters.MoskitoCommandFilter.doFilter(MoskitoCommandFilter.java:26)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at x.y.z.common.web.useragent.TouchScreenDeviceFilter.doFilter(TouchScreenDeviceFilter.java:42)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at x.y.z.common.web.LandingPageFilter.doFilter(LandingPageFilter.java:44)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at x.y.z.common.web.CharsetFilter.doFilter(CharsetFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:397)
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.rewrite.RewriteValve.invoke(RewriteValve.java:466)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)
    at java.lang.Thread.run(Thread.java:722)

grepping netstat输出显示在CLOSE_WAIT中有817个连接,在此ip中有3个处于ESTABLISHED状态。

accesslogs显示:

140.206.78.100 [13/Feb/2013:15:20:48 +0100] http--0.0.0.0-8443-364 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1276 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:50 +0100] http--0.0.0.0-8443-364 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1259 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:51 +0100] http--0.0.0.0-8443-477 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 2991 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:53 +0100] http--0.0.0.0-8443-428 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 2456 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:54 +0100] http--0.0.0.0-8443-639 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1305 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:54 +0100] http--0.0.0.0-8443-491 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1326 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:56 +0100] http--0.0.0.0-8443-491 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1293 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:57 +0100] http--0.0.0.0-8443-663 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1315 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:20:59 +0100] http--0.0.0.0-8443-663 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 1277 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
140.206.78.100 [13/Feb/2013:15:21:02 +0100] http--0.0.0.0-8443-225 GET  o1uNdliDOQhJkDnbvXo4RIZ2.undefined 2427 HTTP/1.1 443 / 200 Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
1

我们使用Jboss AS 7,java 6/7(试过两者),ubuntu on vm,ssl offloading和loadbalancing with alteon loadbalancer。

PS: 添加了netstat示例,其中三个:

tcp        0      0 my.public.ip:8443       140.206.78.100:14186    ESTABLISHED
tcp        0  35040 my.public.ip:8443       140.206.78.100:14620    ESTABLISHED
tcp        0  35040 my.public.ip:8443       140.206.78.100:13859    ESTABLISHED

和其中的817个:

tcp        1  35040 my.public.ip:8443       140.206.78.100:13233    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11649    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11605    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11892    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:13692    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11988    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:13055    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:13242    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:13073    CLOSE_WAIT 
tcp        1  37960 my.public.ip:8443       140.206.78.100:10176    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:14557    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:12288    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:12509    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11049    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:11839    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:14208    CLOSE_WAIT 
tcp        1  35040 my.public.ip:8443       140.206.78.100:14662    CLOSE_WAIT

1 个答案:

答案 0 :(得分:2)

您正在遭受拒绝服务攻击。客户端IP地址黑名单。