tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Who ate my "Connection reset by peer" SocketException?
Date Thu, 04 Aug 2011 16:19:58 GMT
Debashis Roy wrote:
> Hi,
>  
> Trying something which involves catching the "Connection reset by peer" SocketException.
Below is the code snippet from my servlet with explanatory comments.
> Does anyone have any idea as to what is happening?
>  
> try
> {
>  byte [] bytes = getContentBytes(); //read the actual bytes of the content into an array.
>  resp.addHeader("Content-Disposition", "attachment;filename=somefile.zip");
>  resp.addHeader("Content-Type", "application/zip");
>  resp.addHeader("Pragma", "no-cache");
>  resp.addHeader("Connection", "close");
>  resp.setContentLength(bytes.length);
>  OutputStream os = resp.getOutputStream();
>  for (int i = 0; i < bytes.length; i++)
>  {
>   System.out.println("writing byte " + i);
>   os.write(bytes[i]);
>   /* write all bytes but the last one to the ostream */
>   /* the file save dialog shows up in the browser */
>   /* netstat shows an established connection from browser to 8080 of tomcat host */
>   if (i == bytes.length - 2)
>   {
>    System.out.println("doing intermediate flush...");
>    resp.flushBuffer();
>    /* sleep for 30 secs */
>    /* during this time close the browser and click cancel on the file save dialog*/
>    /* netstat shows zero connections with port 8080 of tomcat */
>    try
>    {
>     Thread.sleep(30000);
>    }
>    catch (InterruptedException interex)
>    {
>    }
>   }
>   /* the last byte gets written after the sleep period */
>   /* was expecting to see the "connection reset by peer" exception here */
>  }
>  /* or here */
>  resp.flushBuffer();
>  
>  /* Voila !!! no exceptions till here and the code exits cleanly !!! */
> }
> catch (Throwable th)
> {
>  th.printStackTrace();
> }
>  		 	   		  

Is there anything at all between the browser and Tomcat ?
(thinking of a front-end webserver/load balancer etc..)



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message