You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Emmanuel Lécharny <el...@symas.com> on 2015/09/17 16:43:17 UTC

localhost/127.0.0.1 problems...

Hi !

I was suprisingly hit another time by a failing test, where the client
is trying to connect to a server using "localhost" when the server was
listening on "127.0.0.1".

I think we should get rid of those two Strings in our code (mainly tests).

There is a way to get the localhost and its name in java :

    String hostName = InetAddress.getLocalHost().getHostName();

and

    InetAddress hostName = InetAddress.getLocalHost();


This is what we should use.

Thoughts ?

Re: localhost/127.0.0.1 problems...

Posted by Radovan Semancik <ra...@evolveum.com>.
Hi,

The problem is probably that "localhost" resolves to IPv6 address and 
"127.0.0.1" to IPv4 address. Using either "localhost" or "127.0.0.1" 
consistently in all the tests should resolve the problem. Getting the 
localhost from InetAddress.getLocalHost() seems to be more elegant, 
though. And it should also work reliably IFAIK.

-- 
Radovan Semancik
Software Architect
evolveum.com



On 09/17/2015 04:43 PM, Emmanuel Lécharny wrote:
> Hi !
>
> I was suprisingly hit another time by a failing test, where the client
> is trying to connect to a server using "localhost" when the server was
> listening on "127.0.0.1".
>
> I think we should get rid of those two Strings in our code (mainly tests).
>
> There is a way to get the localhost and its name in java :
>
>      String hostName = InetAddress.getLocalHost().getHostName();
>
> and
>
>      InetAddress hostName = InetAddress.getLocalHost();
>
>
> This is what we should use.
>
> Thoughts ?



Re: localhost/127.0.0.1 problems...

Posted by Stefan Seelmann <ma...@stefan-seelmann.de>.
On 09/17/2015 04:43 PM, Emmanuel Lécharny wrote:
> Hi !
> 
> I was suprisingly hit another time by a failing test, where the client
> is trying to connect to a server using "localhost" when the server was
> listening on "127.0.0.1".
> 
> I think we should get rid of those two Strings in our code (mainly tests).
> 
> There is a way to get the localhost and its name in java :
> 
>     String hostName = InetAddress.getLocalHost().getHostName();
> 
> and
> 
>     InetAddress hostName = InetAddress.getLocalHost();
> 
> 
> This is what we should use.
> 
> Thoughts ?
> 

Makes totally sense.

However I remember that there we had always issues with different Java
versions (Java 6, 7, 8), OS (Linux, Mac, Windows) and network stack (v4,
v6, /etc/hosts file, DNS). Let's hope the best...