You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Jeff C <ca...@yahoo.com> on 2007/05/08 21:00:08 UTC

running out of ports

I was having the following issue using the standard Java package so I was recommended to try out HttpClient and I still have the same issue.  Perhaps someone can shed some light on the situation for me?
   
  Let's say I want to download many files that happen to _not exist_ on the server.  For example:
   
  http://www.example.com/notThere1.txt
  http://www.example.com/notThere2.txt
  http://www.example.com/notThere3.txt
  ...
  http://www.example.com/notThere5000.txt
   
  What ends up happening is that after notThere1.txt is found to be not there, attempting to download notThere2.txt actually uses a different local port.  And eventually, I run out of ports because all of the ones I had been using are stuck in the TIME_WAIT state.  
   
  I am using Windows XP.
  The code I have written essentially looks like the sample code in the tutorial.  To be more specific, the code is exactly the same if the file doesn't exist (which is the only case I'm testing), and different for when it does exist.
   
  I appreciate any help.  Thanks!

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

Re: running out of ports

Posted by Roland Weber <os...@dubioso.net>.
Hi Jeff,

Jeff C wrote:
> Thanks!  Now I'm wondering why this is happening in the first place.  When
> the files _do_ exist on the server, then my application largely doesn't use
> different ports.  So, is it the case that when I find out the file doesn't
> exist on the server that it automatically forcefully terminates the
> connection and does the ending tcp handshake (which therefore eventually
> leads us to the TIME_WAIT state and renders that port unusable, even though
> I still want to use it retrieve other files that may be on the same
> server)?  If so, is there a way to prevent that from happening and leave
> the connection open?

A connection can only be kept open if _both_ client and server agree
to use it for a subsequent request. HttpClient will always try to
keep connections alive. If the server decides not do that, you'll
have to fix the server. Personally, I think it is only prudent of
a server to not re-use connections over which an error response has
been sent. It is easy to forget that error responses come with a
message body.
You might try to send a HEAD instead of a GET request to see whether
that makes a difference. I doubt it, though.

cheers,
  Roland

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


RE: running out of ports

Posted by Jeff C <ca...@yahoo.com>.
Thanks!  Now I'm wondering why this is happening in the first place.  When the files _do_ exist on the server, then my application largely doesn't use different ports.  So, is it the case that when I find out the file doesn't exist on the server that it automatically forcefully terminates the connection and does the ending tcp handshake (which therefore eventually leads us to the TIME_WAIT state and renders that port unusable, even though I still want to use it retrieve other files that may be on the same server)?  If so, is there a way to prevent that from happening and leave the connection open?
   
  Thanks,
   
  Jeffrey

Roland Weber <RO...@de.ibm.com> wrote:
  Hello Jeffrey,

> Thanks! What I was wondering though was why different ports are 
> being used, and if there was a way to resolve that issue.

Different ports are being used because Windows does not release
the old ones in a timely fashion. You have to change Windows settings
to speed up the release, while at the same time allowing more ports.
I posted some links on this mailing list a few weeks ago, please
search the archive.

hope that helps,
Roland



 
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.

RE: running out of ports

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Jeffrey,

> Thanks!  What I was wondering though was why different ports are 
> being used, and if there was a way to resolve that issue.

Different ports are being used because Windows does not release
the old ones in a timely fashion. You have to change Windows settings
to speed up the release, while at the same time allowing more ports.
I posted some links on this mailing list a few weeks ago, please
search the archive.

hope that helps,
  Roland


RE: running out of ports

Posted by Jeff C <ca...@yahoo.com>.
Thanks!  What I was wondering though was why different ports are being used, and if there was a way to resolve that issue.  I don't want my application to use up all 5000 ports in the first place.
   
  Jeffrey

Anders Wallgren <an...@electric-cloud.com> wrote:
  Windows, by default, limits the number of ephemeral ports to 5000. Read
http://support.microsoft.com/kb/196271 to find out how to increase this
number.

anders

-----Original Message-----
From: Jeff C [mailto:calshines2006@yahoo.com] 
Sent: Tuesday, May 08, 2007 12:00 PM
To: httpclient-user@jakarta.apache.org
Subject: running out of ports

I was having the following issue using the standard Java package so I
was recommended to try out HttpClient and I still have the same issue.
Perhaps someone can shed some light on the situation for me?

Let's say I want to download many files that happen to _not exist_ on
the server. For example:

http://www.example.com/notThere1.txt
http://www.example.com/notThere2.txt
http://www.example.com/notThere3.txt
...
http://www.example.com/notThere5000.txt

What ends up happening is that after notThere1.txt is found to be not
there, attempting to download notThere2.txt actually uses a different
local port. And eventually, I run out of ports because all of the ones
I had been using are stuck in the TIME_WAIT state. 

I am using Windows XP.
The code I have written essentially looks like the sample code in the
tutorial. To be more specific, the code is exactly the same if the file
doesn't exist (which is the only case I'm testing), and different for
when it does exist.

I appreciate any help. Thanks!


---------------------------------
Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org



       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

RE: running out of ports

Posted by Anders Wallgren <an...@electric-cloud.com>.
Windows, by default, limits the number of ephemeral ports to 5000.  Read
http://support.microsoft.com/kb/196271 to find out how to increase this
number.

anders

-----Original Message-----
From: Jeff C [mailto:calshines2006@yahoo.com] 
Sent: Tuesday, May 08, 2007 12:00 PM
To: httpclient-user@jakarta.apache.org
Subject: running out of ports

I was having the following issue using the standard Java package so I
was recommended to try out HttpClient and I still have the same issue.
Perhaps someone can shed some light on the situation for me?
   
  Let's say I want to download many files that happen to _not exist_ on
the server.  For example:
   
  http://www.example.com/notThere1.txt
  http://www.example.com/notThere2.txt
  http://www.example.com/notThere3.txt
  ...
  http://www.example.com/notThere5000.txt
   
  What ends up happening is that after notThere1.txt is found to be not
there, attempting to download notThere2.txt actually uses a different
local port.  And eventually, I run out of ports because all of the ones
I had been using are stuck in the TIME_WAIT state.  
   
  I am using Windows XP.
  The code I have written essentially looks like the sample code in the
tutorial.  To be more specific, the code is exactly the same if the file
doesn't exist (which is the only case I'm testing), and different for
when it does exist.
   
  I appreciate any help.  Thanks!

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org