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不能讀取這麼多數據,我改成循環多次讀取即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章