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 Erxiang Liu <er...@us.ibm.com> on 2007/03/16 16:04:18 UTC

java.net.BindException on windows vista

Hello, all:

we got some exception when using apache to open a http connection,

 this seems a windows vista issue only. can  anyone  throw some light?
Here is the exception:

java.net.BindException: Address already in use: NET_Bind
      at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
      at java.net.Socket.bind(Socket.java:587)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
      at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:615)
      at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:138)
      at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:124)
      at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)
      at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)
      at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
      at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)


thanks,

Michelle

Re: java.net.BindException on windows vista

Posted by Roland Weber <ht...@dubioso.net>.
And here's another workaround you might try:
http://publib.boulder.ibm.com/infocenter/cicsts/v2r2/index.jsp?topic=/com.ibm.cicstg600.doc/ccllal0264.htm

I found it via
http://forum.java.sun.com/thread.jspa?threadID=5044757&tstart=45


cheers,
  Roland

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


Re: java.net.BindException on windows vista

Posted by Erxiang Liu <er...@us.ibm.com>.

Thanks, Roland!

This problem can only be recreatble in IBM JVM on some windows vista when
using apache code, J9 works fine. Did not try Sun JVM yet.

Michelle



                                                                           
             Roland Weber                                                  
             <ROLWEBER@de.ibm.                                             
             com>                                                       To 
                                       "HttpClient User Discussion"        
             03/30/2007 12:51          <httpclient-user@jakarta.apache.org 
             AM                        >                                   
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
             "HttpClient User          Re: java.net.BindException on       
                Discussion"            windows vista                       
             <httpclient-user@                                             
             jakarta.apache.or                                             
                    g>                                                     
                                                                           
                                                                           
                                                                           




Hello Michelle,

> Fatal transport error: Address already in use: NET_Bind
> java.net.BindException: Address already in use: NET_Bind
> at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
>
> I also wrote the code use apache client directly and it also causes
> the same exception.
>
> this made me think this may be an apache bug.

Socket opening is not under control of HttpClient. HttpClient
calls a ProtocolSocketFactory, which calls a standard Java API
to open a socket.
Apparently, HttpURLConnection does something differently.
If it is known what the difference is, there is a chance of
adding a workaround to HttpClient, or at least to document
how to work around the problem.

Have you tried to rip out all the HTTP communication and
just perform the socket opening and closing alone? Maybe
with sending some hard-coded request. I'm sure you'll be
able to reproduce this problem without any HttpClient
code being executed.

> The wield thing is we
> can only recreate this problem in some of vista machines, but not
> all vista machines. And it works fine on windows XP. Could this be
> an apache bug?

No, because the HttpClient code seems to work fine on all
other platforms. At most, it is an incompatibility of the
HttpClient code with Vista. In that case, it is up for debate
whether Vista/JVM or HttpClient should be changed. But changing
HttpClient - if we knew what needs to be done - means changing
the behavior on *all* platforms, which is a higher risk.

> if so, what is the process to open an apache bug?

For HttpClient, issues are tracked in JIRA:
http://jakarta.apache.org/commons/httpclient/issue-tracking.html

You can open an issue for tracking purposes. But you should
understand that the developer community of HttpClient is
rather small, and probably does not have the resources to
recreate this problem on Vista. In particular since you
report that it occurs only on *some* of your Vista machines.

FWIW, I think your best chance to get this resolved is to
re-create the problem without HttpClient, just by using plain
old sockets. Then you can report it to Hursely. Btw, are these
problems with the full SUN/IBM JVM, or with J9?

> Also, is there anyway to tune the system settings instead of
> changing the code as you recommended below to solve this problem?

That can only be answered by someone with access to
a Vista system where the problem can be reproduced.

cheers,
  Roland


Re: java.net.BindException on windows vista

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

> Fatal transport error: Address already in use: NET_Bind
> java.net.BindException: Address already in use: NET_Bind
> at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
> 
> I also wrote the code use apache client directly and it also causes 
> the same exception.
> 
> this made me think this may be an apache bug.

Socket opening is not under control of HttpClient. HttpClient
calls a ProtocolSocketFactory, which calls a standard Java API
to open a socket.
Apparently, HttpURLConnection does something differently.
If it is known what the difference is, there is a chance of
adding a workaround to HttpClient, or at least to document
how to work around the problem.

Have you tried to rip out all the HTTP communication and
just perform the socket opening and closing alone? Maybe
with sending some hard-coded request. I'm sure you'll be
able to reproduce this problem without any HttpClient
code being executed.

> The wield thing is we 
> can only recreate this problem in some of vista machines, but not 
> all vista machines. And it works fine on windows XP. Could this be 
> an apache bug?

No, because the HttpClient code seems to work fine on all
other platforms. At most, it is an incompatibility of the
HttpClient code with Vista. In that case, it is up for debate
whether Vista/JVM or HttpClient should be changed. But changing
HttpClient - if we knew what needs to be done - means changing
the behavior on *all* platforms, which is a higher risk.

> if so, what is the process to open an apache bug?

For HttpClient, issues are tracked in JIRA:
http://jakarta.apache.org/commons/httpclient/issue-tracking.html

You can open an issue for tracking purposes. But you should
understand that the developer community of HttpClient is
rather small, and probably does not have the resources to
recreate this problem on Vista. In particular since you
report that it occurs only on *some* of your Vista machines.

FWIW, I think your best chance to get this resolved is to
re-create the problem without HttpClient, just by using plain
old sockets. Then you can report it to Hursely. Btw, are these
problems with the full SUN/IBM JVM, or with J9?

> Also, is there anyway to tune the system settings instead of 
> changing the code as you recommended below to solve this problem?

That can only be answered by someone with access to
a Vista system where the problem can be reproduced.

cheers,
  Roland


Re: java.net.BindException on windows vista

Posted by Erxiang Liu <er...@us.ibm.com>.
Roland:

we have the test code that simply open a connection, If it is using the
default JVM http url handler , it works fine. But if we use or our
customized http url handler, which calls the apache http client code, it
would fail with the trace like this.
Fatal transport error: Address already in use: NET_Bind
java.net.BindException: Address already in use: NET_Bind
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
        at java.net.Socket.bind(Socket.java:587)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:64)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:615)
        at
org.apache.commons.httpclient.protocol.ReflectionSocketFactory.create
Socket(ReflectionSocketFactory.java:138)
        at
org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.c
reateSocket(DefaultProtocolSocketFactory.java:124)
        at
org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java
:706)
        at
org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$Http
ConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1321)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Htt
pMethodDirector.java:386)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMe
thodDirector.java:170)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.jav
a:396)

the test code looks like this :
            request_url = new URL("http://www.oreilly.com");
            HttpURLConnection hcon = (HttpURLConnection)
request_url.openConnection();
            int result = hcon.getResponseCode();
I also wrote the code use apache client directly and it also causes the
same exception.

this made me think this may be an apache bug.  The wield thing is we can
only recreate this problem in some of vista machines, but not all vista
machines. And it works fine on windows XP. Could this be an apache bug? if
so, what is the process to open an apache bug?

Also, is there anyway to tune the system settings instead of changing the
code as you recommended below to solve this problem?


thanks,

Michell:



                                                                           
             Roland Weber                                                  
             <http-async@dubio                                             
             so.net>                                                    To 
                                       HttpClient User Discussion          
             03/19/2007 02:20          <httpclient-user@jakarta.apache.org 
             PM                        >                                   
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
             "HttpClient User          Re: java.net.BindException on       
                Discussion"            windows vista                       
             <httpclient-user@                                             
             jakarta.apache.or                                             
                    g>                                                     
                                                                           
                                                                           
                                                                           




Hi Michelle,

> I think you are right.  the apache httpclient code seems  hardcoded the
> local port to 0 when creating a socket. Sounds like this should not be a
> vista specific issue.

Port 0 is never used as a port number. Specifying 0 indicates to the OS
that any free port is acceptable. Looks like Vista, or the JVM on Vista,
doesn't know which ports are free.
>
> This depends on some low level settings related to address re-use.
>
> just wonder how you find those low level settings and maybe change it and
> make it working?

try this one:
http://java.sun.com/j2se/1.4.2
/docs/api/java/net/Socket.html#setReuseAddress(boolean)

Create a custom ProtocolSocketFactory to contain the modified code:
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html


It needs to be registered for Protocol "http":
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/Protocol.html#registerProtocol(java.lang.String,%20org.apache.commons.httpclient.protocol.Protocol)



hope that helps,
  Roland

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


Re: java.net.BindException on windows vista

Posted by Roland Weber <ht...@dubioso.net>.
Hi Michelle,

> I think you are right.  the apache httpclient code seems  hardcoded the
> local port to 0 when creating a socket. Sounds like this should not be a
> vista specific issue.

Port 0 is never used as a port number. Specifying 0 indicates to the OS
that any free port is acceptable. Looks like Vista, or the JVM on Vista,
doesn't know which ports are free.
> 
> This depends on some low level settings related to address re-use.
> 
> just wonder how you find those low level settings and maybe change it and
> make it working?

try this one:
http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html#setReuseAddress(boolean)

Create a custom ProtocolSocketFactory to contain the modified code:
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html

It needs to be registered for Protocol "http":
http://jakarta.apache.org/commons/httpclient/apidocs/org/apache/commons/httpclient/protocol/Protocol.html#registerProtocol(java.lang.String,%20org.apache.commons.httpclient.protocol.Protocol)


hope that helps,
  Roland

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


Re: java.net.BindException on windows vista

Posted by Erxiang Liu <er...@us.ibm.com>.
thanks, Roland:

I think you are right.  the apache httpclient code seems  hardcoded the
local port to 0 when creating a socket. Sounds like this should not be a
vista specific issue.

This depends on some low level settings related to address re-use.

just wonder how you find those low level settings and maybe change it and
make it working?

thanks,

Michelle



                                                                           
             Roland Weber                                                  
             <http-async@dubio                                             
             so.net>                                                    To 
                                       HttpClient User Discussion          
             03/19/2007 01:02          <httpclient-user@jakarta.apache.org 
             PM                        >                                   
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
             "HttpClient User          Re: java.net.BindException on       
                Discussion"            windows vista                       
             <httpclient-user@                                             
             jakarta.apache.or                                             
                    g>                                                     
                                                                           
                                                                           
                                                                           




Hello Michelle,

>  this seems a windows vista issue only. can  anyone  throw some light?
> Here is the exception:
>
> java.net.BindException: Address already in use: NET_Bind

I assume you were to trying to bind the socket locally to a specific
port number. In that case it is a problem with Windows choosing a
free port. If you were trying to bind to a specific port locally,
that one was already in use. Note that even after a socket is closed,
the port to which it was bound can remain blocked for some time.
This depends on some low level settings related to address re-use.

hope this helps,
  Roland


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


Re: java.net.BindException on windows vista

Posted by Roland Weber <ht...@dubioso.net>.
Hello Michelle,

>  this seems a windows vista issue only. can  anyone  throw some light?
> Here is the exception:
> 
> java.net.BindException: Address already in use: NET_Bind

I assume you were to trying to bind the socket locally to a specific
port number. In that case it is a problem with Windows choosing a
free port. If you were trying to bind to a specific port locally,
that one was already in use. Note that even after a socket is closed,
the port to which it was bound can remain blocked for some time.
This depends on some low level settings related to address re-use.

hope this helps,
  Roland


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