You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Debashis Roy <r_...@hotmail.com> on 2011/08/04 12:16:18 UTC

Who ate my "Connection reset by peer" SocketException?

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();
}
 		 	   		  

RE: Who ate my "Connection reset by peer" SocketException?

Posted by Debashis Roy <r_...@hotmail.com>.
Thanks for the lead guys. Looks like something is there could be the windows firewall.
Both tomcat and browser are on the same machine. Tried accessing the service using localhost, got the exception.
Tried using IP address, no exception :(.
Any trick using which I can get this exception reliably? I am already using the header Pragma: no-cache.

 

> Date: Thu, 4 Aug 2011 14:01:16 -0400
> From: dckerber@verizon.net
> To: users@tomcat.apache.org
> Subject: Re: Who ate my "Connection reset by peer" SocketException?
> 
> On 8/4/2011 1:38 PM, Debashis Roy wrote:
> >
> > Nothing in between browser and tomcat... direct connection from IE to 8080.
> 
> Not even a router? What about the windows firewall?
> 
> 
> >
> >
> >> Date: Thu, 4 Aug 2011 18:19:58 +0200
> >> From: aw@ice-sa.com
> >> To: users@tomcat.apache.org
> >> Subject: Re: Who ate my "Connection reset by peer" SocketException?
> >>
> >> 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
> >>
> > 
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
 		 	   		  

Re: Who ate my "Connection reset by peer" SocketException?

Posted by David kerber <dc...@verizon.net>.
On 8/4/2011 1:38 PM, Debashis Roy wrote:
>
> Nothing in between browser and tomcat... direct connection from IE to 8080.

Not even a router?  What about the windows firewall?


>
>
>> Date: Thu, 4 Aug 2011 18:19:58 +0200
>> From: aw@ice-sa.com
>> To: users@tomcat.apache.org
>> Subject: Re: Who ate my "Connection reset by peer" SocketException?
>>
>> 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
>>
>   		 	   		
>


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


RE: Who ate my "Connection reset by peer" SocketException?

Posted by Debashis Roy <r_...@hotmail.com>.
Nothing in between browser and tomcat... direct connection from IE to 8080.
 

> Date: Thu, 4 Aug 2011 18:19:58 +0200
> From: aw@ice-sa.com
> To: users@tomcat.apache.org
> Subject: Re: Who ate my "Connection reset by peer" SocketException?
> 
> 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
> 
 		 	   		  

Re: Who ate my "Connection reset by peer" SocketException?

Posted by André Warnier <aw...@ice-sa.com>.
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