我们java.net.SocketException: Connection reset
在日志中看到频繁但间歇性的 错误.我们不确定Connection reset
错误实际来自何处,以及如何进行调试.
该问题似乎与我们尝试发送的邮件无关.请注意,消息不是 connection reset by peer
.
有关此异常的典型原因可能是什么的建议,以及我们如何进行?
这是一个代表性的堆栈跟踪(com.companyname.mtix.sms
是我们的组件):
java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read(BufferedInputStream.java:235) at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77) at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105) at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115) at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324) at com.companyname.mtix.sms.services.impl.message.SendTextMessage.sendTextMessage(SendTextMessage.java:127) at com.companyname.mtix.sms.services.MessageServiceImpl.sendTextMessage(MessageServiceImpl.java:125) at com.companyname.mtix.sms.services.remote.MessageServiceRemoteImpl.sendTextMessage(MessageServiceRemoteImpl.java:43) at sun.reflect.GeneratedMethodAccessor203.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.companyname.mtix.sms.http.filters.NoCacheFilter.doFilter(NoCacheFilter.java:63) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at com.companyname.mtix.sms.http.filters.MessageFilter.doFilter(MessageFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:61) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.ajaxanywhere.AAFilter.doFilter(AAFilter.java:46) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595)
我们的组件是一个在Tomcat下运行的Web应用程序,它调用发送SMS消息的第三方Web服务.从中抛出异常的代码行是下面代码片段中的最后一行.
String aggregatorResponse = null; HttpClient httpClient = prepareHttpClient( username, password ); PostMethod postMethod = preparePostMethod( textUrl ); try { SybaseTextMessageBuilder builder = new SybaseTextMessageBuilder(); URL notifyUrl = buildNotificationUrl( textMessage, codeSetManager ); String smsRequestDocument = builder.buildTextMessage( textMessage, notifyUrl ); LOG.debug( "Sybase MT document created as: \n" + smsRequestDocument ); postMethod.setRequestEntity( new StringRequestEntity( smsRequestDocument ) ); LOG.debug( "commiting SMS to aggregator: " + textMessage.toString() ); int httpStatus = httpClient.executeMethod( postMethod );
Mark.. 63
SocketException的javadoc声明它是
抛出以指示底层协议中存在错误,例如TCP错误
在您的情况下,似乎连接已被连接的服务器端关闭.这可能是您发送的请求或最终问题的问题.
为了帮助调试,您可以使用Wireshark等工具查看实际的网络数据包.此外,您是否有可用于测试Web服务的Java代码的替代客户端?如果成功,则可能表明Java代码中存在错误.
当您使用Commons HTTP Client时,请查看Common HTTP Client Logging Guide.这将告诉您如何在HTTP级别记录请求.
SocketException的javadoc声明它是
抛出以指示底层协议中存在错误,例如TCP错误
在您的情况下,似乎连接已被连接的服务器端关闭.这可能是您发送的请求或最终问题的问题.
为了帮助调试,您可以使用Wireshark等工具查看实际的网络数据包.此外,您是否有可用于测试Web服务的Java代码的替代客户端?如果成功,则可能表明Java代码中存在错误.
当您使用Commons HTTP Client时,请查看Common HTTP Client Logging Guide.这将告诉您如何在HTTP级别记录请求.
这个错误发生在你身边而不是另一边.如果另一方重置连接,则异常消息应该说:
java.net.SocketException reset by peer
原因是里面的连接HttpClient
是陈旧的.检查SSL的陈旧连接不会修复此错误.解决方案:转储您的客户端并重新创建.
如果您尝试访问部署在Glassfish3服务器上的Web服务,则可能需要调整http-thread-pool设置.修复了许多并发线程调用Web服务时我们遇到的SocketExceptions.
转到管理控制台
导航到"配置" - >"服务器配置" - >"线程池" - >"http-thread-pool".
将"最大线程池大小"设置从5更改为32
将"最小线程池大小"设置从2更改为16
重启Glassfish.
我也偶然发现了这个错误.在我的情况下问题是我使用JRE6,支持TLS1.0.服务器仅支持TLS1.2,因此抛出此错误.
在我的情况下,这是因为我的Tomcat设置不足以maxHttpHeaderSize
进行特别复杂的SOLR查询.
希望这有助于那里的人!
我总是得到这个错误并认为这是正常的.
当一方在另一方已经挂断时试图读取时,会发生这种情况.因此,根据协议,这可能会或可能不会指出问题.如果我的客户端代码专门向服务器指示它将挂断,则客户端和服务器可以同时挂断,并且不会发生此消息.
我实现代码的方式是让客户端挂起而不说再见.然后,服务器可以捕获错误并忽略它.在HTTP的上下文中,我相信协议的一个级别允许每个连接多于一个请求而另一个不允许.
因此,你可以看到一方有可能继续挂在另一方.我怀疑你收到的错误是任何海盗问题,你可以简单地抓住它以防止它填满你的日志文件.