Subject Re: [Firebird-Java] GDS Exception. 335544721 using localhost from apache/tomcat
Author Mark Rotteveel
On 23-12-2013 20:30, Mark Rotteveel wrote:
> Have you tried using 127.0.0.1 instead of localhost? If that works the
> problem is that Java prefers to use the IPv6 address ::1 instead of
> 127.0.0.1 when resolving localhost.
>
> Firebird only supports IPv4, so it only listens (and accepts
> connections) on IPv4. The reason that isql works is that it only
> connects to IPv4.
>
> With Jaybird you either need to specify the IP address, or start Java
> (tomcat) with -Djava.net.preferIPv4Stack=true
>
> I have no explanation for the observed differences in behavior between
> the two machines, although it could be that one returns the IPv4 address
> first, and the other second.
>
> What is the result for the following code on both machines:
>
> for (InetAddress address : InetAddress.getAllByName("localhost")) {
> System.out.println(address);
> }
>
> (preferably from within the tomcat process).

The difference could also be that the system property
java.net.preferIPv6Addresses is set to true on the failing system (see
http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html#Ipv4IPv6
:

"When dealing with a host which has both IPv4 and IPv6 addresses, and if
IPv6 is available on the operating system, the default behavior is to
prefer using IPv4 addresses over IPv6 ones. This is to ensure backward
compatibility, for example applications that depend on the
representation of an IPv4 address (e.g. 192.168.1.1). This property can
be set to true to change that preference and use IPv6 addresses over
IPv4 ones where possible."

You might want to print out the values of:
System.out.println(System.getProperty("java.net.preferIPv4Stack"));
System.out.println(System.getProperty("java.net.preferIPv6Addresses"));

For both tomcat processes

(if it prints null, then it isn't set and defaults to false).
--
Mark Rotteveel