困扰我多年的Connection reset问题

第一次出现:是thrift的python client去请求server,发现偶尔出现这个问题

第二次:接入第三方的api,去请求数据时,发现一个接入方的api第一次总是报这个错,当时又没有做处理,导致获得信息置空,入缓存后数据就是错误的。做了一个更改就是retry三次,得到解决。

第三次:最近去抓appstore的应用指数又重新出现该问题,使用HttpRequestRetryHandler 重试,设置到20次都无一次成功。

堆栈错误信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[app][index-error]: ScreenAnts HD ; priority empty
2014-01-26 14:59:30,668 - I/O exception (java.net.SocketException) caught when processing request: Connection reset
2014-01-26 14:59:30,703 - Retrying request
2014-01-26 14:59:30,668 - [SimpleHttpClient] myRetryHandler, IOException:Connection reset
2014-01-26 14:59:30,668 - I/O exception (java.net.SocketException) caught when processing request: Connection reset
2014-01-26 14:59:30,704 - Retrying request
2014-01-26 14:59:30,668 - I/O exception (java.net.SocketException) caught when processing request: Connection reset
2014-01-26 14:59:30,704 - Retrying request
2014-01-26 14:59:30,704 - [SimpleHttpClient] myRetryHandler, IOException:Connection reset
2014-01-26 14:59:30,704 - [SimpleHttpClient] read http://search.itunes.apple.com/WebObjects/MZSearchHints.woa/wa/hints?q=Deadliest+Animals failed
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:185)
    at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:136)
    at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:152)
    at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:270)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:140)
    at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
    at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
    at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:161)
    at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.http.impl.conn.CPoolProxy.invoke(CPoolProxy.java:138)
    at $Proxy7.receiveResponseHeader(Unknown Source)
    at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:253)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at com.fanxer.aso.index.utils.SimpleHttpClient.getContent(SimpleHttpClient.java:135)
    at com.fanxer.aso.index.task.AppIndexTask.getXmlBytesFromSearchLink(AppIndexTask.java:163)
    at com.fanxer.aso.index.task.AppIndexTask.access$000(AppIndexTask.java:40)
    at com.fanxer.aso.index.task.AppIndexTask$1.call(AppIndexTask.java:98)
    at com.fanxer.aso.index.task.AppIndexTask$1.call(AppIndexTask.java:93)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:679)

  

http://bbs.csdn.net/topics/210061352 解释了四种socket异常:

java.net.SocketException: (Connection reset或者Connect reset by peer:Socket write error)。该异常在客户端和服务器端均有可能发生,引起该异常的原因有两个,第一个就是如果一端的Socket被关闭(或主动关闭或者因为异常退出而引起的关闭),另一端仍发送数据,发送的第一个数据包引发该异常(Connect reset by peer)。另一个是一端退出,但退出时并未关闭该连接,另一端如果在从连接中读数据则抛出该异常(Connection reset)。简单的说就是在连接断开后的读和写操作引起的。

经多次测试发现,50个线程并发,最大的连接时间超过了90秒,平均请求结果仅有400KB,很奇怪的现象。猜测是appstore端连接时间过长直接断开连接(是我被连90s也要断啊)。修改下超时,只能让请求更快恢复,

RetryExec.execute 时仍然无法正常连接。

查看源码,InternalHttpClient继承了CloseableHttpClient 实现了父类的抽象方法

protected abstract CloseableHttpResponse doExecute(HttpHost target, HttpRequest request,
HttpContext context) throws IOException, ClientProtocolException;

对request做了封装,host、config和route确定后,转入execChain

execChain是一系列责任链

RedirectExec ->RetryExec ->ProtocolExec->MainClientExec

转给 HttpRequestExecutor 执行请求, 通过DefaultBHttpClientConnection把结果写入response,看程序没发现问题,终于无意中使用curl做测试,发现也是失败

curl: (56) Failure when receiving data from the peer

目前只能通过降低请求频率或优化降低请求次数或者发现错误时多停顿一段时间去解决。

Connection reset问题,INFO: I/O exception (java.net.SocketException) caught when processing reques的更多相关文章

  1. HttpClient I/O exception (java.net.SocketException) caught when processing request: Connect

    转自:http://luan.iteye.com/blog/1820054 I/O exception (java.net.SocketException) caught when processin ...

  2. I/O exception (java.net.SocketException) caught when processing request: Connect

    Exception [一个故障引发的话题] 最近,项目中的短信模块收到一个故障日志,要求我协助调查一下: 2010-05-07 09:22:07,221 [?:?] INFO  httpclient. ...

  3. java.net.SocketException: Connection reset 解决方法

    java.net.SocketException: Connection reset 解决方法 最近纠结致死的一个java报错java.net.SocketException: Connection ...

  4. 最近纠结致死的一个java报错java.net.SocketException: Connection reset 终于得到解决

    自从SEOTcs系统11月份24日更新了一下SEO得分算法以来,一直困扰我的一个问题出现了,java的数据job任务,在执行过程中会经常报以下的错误: “2011-12-03 18:00:32 Def ...

  5. 困扰我多年的Connection reset问题

    第一次出现:是thrift的python client去请求server,发现偶尔出现这个问题 第二次:接入第三方的api,去请求数据时,发现一个接入方的api第一次总是报这个错,当时又没有做处理,导 ...

  6. 一次SocketException:Connection reset 异常排查

    问题描述 上一期的需求上线之后,线上多了一个异常:Connection reset.如下: [2017-03-22 00:45:00 ERROR] [creativeAuditTaskSchedule ...

  7. IPv6调用java后端接口报错:java.net.SocketException: Protocol family unavailable

    目前需求是java后端的接口需要支持IPv6.先确认linux机器已经绑定了IPv6: CMREAD-SV43 apache-tomcat/bin> ifconfig eth0 Link enc ...

  8. 从tcp原理角度理解Broken pipe和Connection reset by peer的区别

    从tcp原理角度理解Broken pipe和Connection reset by peer的区别 http://lovestblog.cn/blog/2014/05/20/tcp-broken-pi ...

  9. redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: 断开的管道 (Write failed)

    昨晚,包发到测试环境中,出现redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: 断开的 ...

随机推荐

  1. JAVA-第一课 环境的配置

    首先 我们需要 下载java的开发工具包 jdk  jdk 的下载地址::http://www.oracle.com/technetwork/java/javase/downloads/index.h ...

  2. 第三方下载控件 用起来还是不错的偶!Aria

    本文主要介绍开源项目Aria的使用. 先在项目里的build 中配置compile 'com.arialyy.aria:Aria:3.1.1' //下载 开始下载 Aria.download(this ...

  3. Elasticsearch基本命令

    检查集群运行情况:    GET ->   localhost:9200/_cat/health?v 查看集群节点列表:    GET ->   localhost:9200/_cat?n ...

  4. 基于OneMap的水利行业共享服务平台搭建步骤

    今天上午再次学习Esri技术培训中心的“GIS服务共享与运维管理——之OneMap解决方案”课程,从中学习了OneMap的产品架构以及基于OneMap共享服务平台的搭建步骤.下面把其中水利行业的共享服 ...

  5. 老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分

    老师的blog整理 .网络编程部分 .网络编程部分 前端部分 django基础部分   老师的blog整理 python基础部分: 宝哥blog: https://www.cnblogs.com/gu ...

  6. Cesium官方教程10--高级粒子特效

    原文地址:https://cesiumjs.org/tutorials/Particle-Systems-More-Effects-Tutorial/ 高级粒子系统特效 这篇教程学习更多的效果,包括天 ...

  7. PAT甲级——A1083 List Grades

    Given a list of N student records with name, ID and grade. You are supposed to sort the records with ...

  8. 让ASPX页面可以提交html标签代码的配置

    1:打开web.config文件,在system.web节点里,添加<httpRuntime requestValidationMode="2.0" /> 2:在asp ...

  9. Spring Boot Starter自定义实现三步曲

    实现自定义的spring boot starter,只需要三步: 1.一个Bean 2.一个自动配置类 3.一个META-INF/spring.factories配置文件 下面用代码演示这三步. 项目 ...

  10. mysqlbinlog: unknown variable 'default-character-set=utf8'

    [xxx@dbhost log]$ mysqlbinlog mysql-bin. mysqlbinlog: unknown variable 'default-character-set=utf8' ...