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

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

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

堆栈错误信息:

[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问题的更多相关文章

  1. Connection reset问题,INFO: I/O exception (java.net.SocketException) caught when processing reques

    困扰我多年的Connection reset问题 第一次出现:是thrift的python client去请求server,发现偶尔出现这个问题 第二次:接入第三方的api,去请求数据时,发现一个接入 ...

  2. Java socket 说明 以及web 出现java.net.SocketException:(Connection reset或者Connectreset by peer:Socket write error)的解释

    另外http://www.cnblogs.com/fengmk2/archive/2007/01/15/using-Socket.html可供参考   一Java socket 说明 所谓socket ...

  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 分析解决(转载)

    文章转自:https://my.oschina.net/xionghui/blog/508758;记录下来以便以后复习查阅; 在使用HttpClient调用后台resetful服务时,“Connect ...

  6. Connection reset原因分析和解决方案

    在使用HttpClient调用后台resetful服务时,“Connection reset”是一个比较常见的问题,有同学跟我私信说被这个问题困扰很久了,今天就来分析下,希望能帮到大家.例如我们线上的 ...

  7. 短连接时出现connection reset问题的原因

    网上摘取的感觉有用的文章,保存下来,让大家学习交流! 在使用HttpClient调用后台resetful服务时,“Connection reset”是一个比较常见的问题,有同学跟我私信说被这个问题困扰 ...

  8. 转:Connection reset原因分析和解决方案

    在使用HttpClient调用后台resetful服务时,“Connection reset”是一个比较常见的问题,有同学跟我私信说被这个问题困扰很久了,今天就来分析下,希望能帮到大家.例如我们线上的 ...

  9. go grpc: connection reset by peer 的一种解决方案

    最近添哥一直反映,他手下的设备以grpc stream的方式向我服务端发送数据.偶然会收到错误.现象如下: 连接已经建立了一段时间,正常使用. 突然client.Send 返回 eof. 客户端有报错 ...

随机推荐

  1. Java基础之在窗口中绘图——移动曲线的控制点(CurveApplet 3 moving the control points)

    Applet程序. import javax.swing.*; import java.awt.*; import java.awt.geom.*; import javax.swing.event. ...

  2. cat *.txt | grep '>' | wc -l

    find the line where the '>' located, and make a statistic.

  3. Secretary Problem

    最好时机问题 n个值 前n/e都不选 然后取第一个大于前n/e个数中最大值的数 选中最大的概率为1/e

  4. Linux入门:运行级别解析

    Linux入门:运行级别解析   一.查看当前运行级别 Ubuntu中,runlevel命令 可以查看当前运行级别: CentOS中,who -r 命令查看当前运行级别:   www.2cto.com ...

  5. [转]MySQL排序原理与案例分析

    这篇文章非常好,就把他转过来 前言      排序是数据库中的一个基本功能,MySQL也不例外.用户通过Order by语句即能达到将指定的结果集排序的目的,其实不仅仅是Order by语句,Grou ...

  6. 纯CSS气泡效果

    http://www.liaoxuefeng.com/article/0013738937970388b6b6e5e5e2f4e21b65b01807c84ddf6000

  7. C语言笔试常考知识点

    1. const 关键字 a)  const int a; b)  int const a; c)  const int *a; d)  int * const a; e)  int const * ...

  8. [问题2015S06] 复旦高等代数 II(14级)每周一题(第七教学周)

    [问题2015S06]  设 \(V\) 是数域 \(\mathbb{K}\) 上的 \(n\) 维线性空间, \(\varphi\) 是 \(V\) 上的线性变换. (1) 求证: 对任一非零向量 ...

  9. 151008:javascript不明白的地方

    http://www.cnblogs.com/ahthw/p/4841405.html,在这里面: function compare(num1, num2){ return num1 - num2; ...

  10. Redis - 发布和订阅

    一.概述 1). 发布和订阅是一种消息通信模式. 2). 优点:使消息订阅者和消息发布者耦合度降低,类似设计模式中的观察者模式. 二.发布和订阅 订阅命令: // 订阅一个或多个频道 // 返回值:v ...