ClientAbortException,Connection reset by peer: socket write error

  extremetable导出excel,弹出一个下载窗口,这时不点下载而点取消,则报下面的异常:
ClientAbortException Caused by: java.net.SocketException: Connection reset by peer: socket write error
查了下TOMCAT的文档,解释如下:
Wrap an IOException identifying it as being caused by an abort of a request by a remote client.
在BAIDU和GOOGLE上找了下原因,大概归结为:
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error的原因是由于处理http连接时,正在输出内容时,用户关闭了IE,会出现一个"ClientAbortException",属于I/O处理中出现的一个异常,应用服务器应该会捕捉。
Connection reset by peer的原因:
经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是:
①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;
②:客户关掉了浏览器,而服务器还在给客户端发送数据;
③:浏览器端按了Stop
很多人都说是客户端造成的,没有办法控制,是个比较郁闷的问题。

但是,我担心的是:虽然前台没有任何出错的迹象,但是后台会记录这个异常,日志也会疯狂爆满,时间长了,肯定会DOWN掉的,还没找到好的解决办法
resin有一个参数ignore-client-disconnect
tomcat似乎没有




经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是:①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;②:客户关掉了浏览器,而服务器还在给客户端发送数据;③:浏览器端按了Stop

[10054] Connection reset by peer
  Connection reset by peer is a tough one because it can be caused by so many things. In all cases, the server determines that the socket is no longer good and closes it from its side.
  Read Error
  Scenario: Mary couldn't make out what Joe was saying anymore, so she hung up rather than lose his messages (data).
  A read error occurs when a server cannot successfully read from a user's client. Servers gather information from the client by text, setup, and other items.When the server receives an error when reading from a client, it then disconnects the user, resulting in a read error quit message.
  Write Error
  Scenario: Mary was trying to talk to Joe but didn't think she was getting through, so she hung rather than lose his messages (data).
  A write error occurs when a server cannot successfully write to a user's client. When the server receives information, it usually responds with information of its own. When the server receives an error when writing to a client, it then disconnects the user, resulting in a write error quit message similar to the read error format.
  Ping Timeout Error
  Scenario: Mary, having been raised in a household with too many kids and always craving attention, keeps asking to make sure that Joe is still on the line and listening. If he doesn't reply fast enough to suit her, she hangs up.
  Servers automatically ping users at a preset time. The reason for this is to ensure the client is still connected to the server. When you see "PING? PONG!" results in your status window, it means the server has pinged your client, and it has responded back with a pong to ensure the server that you are still connected. When this does not happen and you disconnect without the server's knowledge, the server will automatically disconnect the user when it does not receive a response, resulting in a ping timeout. Ping timeouts occur to EVERYONE.
  Broken pipe Error
  Scenario: Mary had picked up a sticky note with a message she needed to relay to Joe, but somehow between her hand and her mouth, the message got misplaced. Mary was trying to talk to Joe but didn't think she was getting through, so she hung up rather than lose his messages (data).
  A broken pipe error occurs when the server knows it has a message but can't seem to use its internal data link to get the data out to the socket.
  Miscellaneous
  Scenario: Lots of other reasons; perhaps the operator broke in and gave Mary a message that made her doubt the validity of the call so she hung up

我在做pdf导出的时候针对大的文件下载过程中点关闭或下载前点取消按钮会报以上错误;先记录下来


Java代码 收藏代码



1,一般是有些客户端已关闭,一些线程因为延迟等原因觉察不到此连接已结束,继续等到到出错

2,客户端那里不停刷或一个访问/刷新没完成前再刷,要让这个无用的线程死掉

3,这个问题一般是客户端在连接还没有完全建立的时候就取消连接,比如用户按了浏览器上面的“停止”按钮,一般来说没有什么问题。但是如果频繁出现,就表示很多客户端连接到Apache服务器的响应时间太长了,可能是网络的问题或者服务器性能问题。

4, 这个问题一般是客户端在连接还没有完全建立的时候就取消连接,比如用户按了浏览器上面的“停止”按钮,一般来说没有什么问题。但是如果频繁出现,就表示很多客户端连接到Apache服务器的响应时间太长了,可能是网络的问题或者服务器性能问题

5,可能你的网络连接存在一些问题,你的数据传输的时候,可能由于时间等待的太久,但是server段设置的连接检验时间限制一定,那么就可能出现这种情况的!

6,不过更常见的原因是:
1:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;
2:客户关掉了浏览器,而服务器还在给客户端发送数据;
3:浏览器端按了Stop;
4:服务器给客户端响应结果给防火墙拦截了。

7,我又查了一些资料,原因如下:
非程序问题,一般是由于与客户端连接中断所致,没有太有效的办法解决。但是可以通过系统调优等手段提高系统吞吐量,减少部分因延迟而中断的连接。

一般免费的Web Server,如Tomcat对长期积累的IO错误解决不完善,会导致迟缓,甚至挡掉。所以,如果你的网站(或系统)访问量较大或至少又一段时间集中访问量大,一定要留意这个问题,因为它可能会使你的系统停滞。

建议:1、提高系统性能 2、有条件的话换用商业WebServer如weblogic

 

 

(二)


当我们用Servlet导出图片,或用JSP导出excel时,会弹出一个下载窗口,这时不点下载而点取消,则报下面的异常:
ClientAbortException Caused by: java.net.SocketException: Connection reset by peer: socket write error

在网上查找了了下原因,大概归结为:
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error的原因是由于处理http连接时,正在输出内容时,用户关闭了IE,会出现一个"ClientAbortException",属于I/O处理中出现的一个异常,应用服务器应该会捕捉。
Connection reset by peer的原因:
经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是:
①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉;
②:客户关掉了浏览器,而服务器还在给客户端发送数据;
③:浏览器端按了Stop

很多人都说是客户端造成的,没有办法控制,而且后台会记录这个异常,日志也会疯狂爆满,时间长了,肯定会DOWN掉的.

本人觉得大多数可能是第二条问题的原因引起的,即大多数浏览器阻止了窗口的弹出,相当于客户关掉了浏览器,可等效于浏览器端按了Stop ,而这时服务器端还在给客户端发送数据,所以产生了上异常,经过本人的测试,发现只需将网站地址(或本机地址)加入"受信任的站点"即可解决问题,因为这样设置了以后,浏览器就不会阻止窗口的弹出了,这样浏览器就会等到服务器端发送完数据后再进行下面的动作.因而异常就不会发生了.

大概设置方式如下:"工具->internet(选项..)->安全->受信任的站点->站点",将地址加入即可.

 

(三)

非常感谢各位,我自己找到了原因所在,并不是关闭的问题,没在finally里写关闭只是代码安全性低点,跟逻辑的正确与否无关,事实上是因为下载的图片太大,而一次性从InputStream不能读取这么多数据,我改成循环多次读取即可

你可能感兴趣的:(Connection)