(110) Connection timed out的错HttpClient 每次请求未close导致 Nginx connect failed (110- Connection timed out)
2016-02-17 16:32
1041 查看
发生了下列的错误:
Connection Failed
连接失败
系统返回以下内容:
(110) Connection timed out
系统使用HttpClient发送报文(会有循环发送情况)到外部系统通过nginx分发,这时nginx会报出 connect failed (110- Connection timed out) 错误( 有一些请求报错,有一些不报,都是不定的 ),在网络中查到的答案大部分都说是因为系统内核错误,因为Nginx调用了gettimeofday()方法,但是我们通过编写C代码调用gettimeofday()方法进行测试,根本无法重现这个BUG,所以想到会不会是因为系统内部的错误。
经过调查发现我们在使用HttpClient发送报文之后 没有关闭连接 ,添加代码:
httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager());
finally { if (httpclient != null && httppost != null){ // 释放连接资源 httppost.releaseConnection(); // 关闭Socket连接 httpclient.getConnectionManager().shutdown(); } }
然后再经过一天一夜的测试发现没有再出现connect failed (110- Connection timed out)这个问题了。
再说一下出现这个问题的猜测:
系统内部( 我们系统有定时器和主动发送 )一直再创建新的httpclient连接并且没有关闭这个连接,一旦出现大量发送报文会导致 系统与Nginx之间的等待的连接过多 ,这样会导致nginx分发出现问题,从而导致nginx报出Connection timed out,因为连接太多了,没有释放,而nginx主动释放连接是有时间的。
相关文章推荐
- 在MainActivity的内部静态类PlaceholderFragment 类中的onCreateView中获取fragment_main.xml中控件
- 关于AI的目标导向型行动计划
- 游戏人工智能开发之6种决策方法
- STL 之随机访问迭代器 http://blog.csdn.net/tangaowen/article/details/7515558
- 使用stl中的 advance和 distance 方法来进行iterator的加减 http://blog.csdn.net/tangaowen/article/details/7515558
- 置顶] 简单的程序诠释C++ STL算法系列之十三:copy http://blog.csdn.net/jerryjbiao/article/details/7376088
- Better Business Grammar Train Summary
- gitlab push时报错error:failed to push some refs to 'git@xxx.xx.xx.xxx:xxxx/xxx.git'
- 【Lintcode】Restore IP Addresses, Number of Airplanes in the Sky
- 无法解决 equal to 运算中 "Chinese_PRC_CI_AS" 和 "Chinese_PRC_90_CI_AI" 之间的排序规则冲突。的解决方法
- LeetCode 217. Contains Duplicate
- Failed to locate or generate matchin signing assets
- process launch failed: Security
- Spark技术内幕:Master基于ZooKeeper的High Availability(HA)源码实现
- Login with RMAN immediately fails with ORA-04031, ORA-06508
- HackerRank "Training the army" - Max Flow
- Something about the microsoft HttpContext domain design
- OORA-38760: This database instance failed to turn on flashback database
- JetBrains系列产品激活
- Error:executing aidl:return code 1