FirebirdSQL / jaybird

JDBC driver for Firebird
https://www.firebirdsql.org/en/jdbc-driver/
GNU Lesser General Public License v2.1
91 stars 23 forks source link

Embedded version of Firebird (used in a Java program on Linux) tries to establish a connection and fails [JDBC111] #151

Closed firebird-automations closed 16 years ago

firebird-automations commented 16 years ago

Submitted by: Arjen Markus (arjenmarkus)

Assigned to: Roman Rokytskyy (rrokytskyy)

We use Jaybird 2.1 and the embedded version of Firebird in a Java program. On Windows this works perfectly, on Linux, however, the initialisation fails:

h3.wldelft.nl Fri Feb 29 12:00:39 2008 INET/inet_error: connect errno = 111

h3.wldelft.nl Fri Feb 29 12:00:41 2008 INET/inet_error: connect errno = 111

h3.wldelft.nl Fri Feb 29 12:00:41 2008 Unable to complete network request to host "hafilere".

h3.wldelft.nl Fri Feb 29 12:00:41 2008 Failed to establish a connection.

h3.wldelft.nl Fri Feb 29 12:00:41 2008 Connection refused

The program raises an exception: org.firebirdsql.gds.impl.jni.InternalError: FirebirdApiBinding::Initialize - Could not find or load the firebird client library. at org.firebirdsql.gds.impl.jni.JniGDSImpl.nativeInitilize(Native Method) at org.firebirdsql.gds.impl.jni.JniGDSImpl.attemptToLoadAClientLibraryFromList(JniGDSImpl.java:85) at org.firebirdsql.gds.impl.jni.EmbeddedGDSImpl.<init>(EmbeddedGDSImpl.java:31) at org.firebirdsql.gds.impl.jni.EmbeddedGDSImpl.<init>(EmbeddedGDSImpl.java:21) at org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin.getGDS(EmbeddedGDSFactoryPlugin.java:40) at org.firebirdsql.gds.impl.GDSFactory.getGDSForType(GDSFactory.java:219) at org.firebirdsql.management.FBManager.start(FBManager.java:98) at nl.wldelft.util.sql.FirebirdConnection.createDatabase(FirebirdConnection.java:124) ...

and terminates.

As we use the libfbembed.so shared object, there should not be any attempt to connect to whatsoever.

The database itself has still to be created at this point - it is a fresh start of the program.

How can we solve this problem or at least analyse why this is happening?

firebird-automations commented 16 years ago

Commented by: Roman Rokytskyy (rrokytskyy)

It is hard to tell where the problem is... The exception you get happens really on the very beginning of the the driver initialization. Few issues are possible:

a) it cannot find the libfbembed.so (should be available via $LD_LIBRARY_PATH) b) libfbembed.so cannot be loaded due to some incompatibilities with your environment.

You can try to build JNI part of the driver from source - use "./build.sh compile-native" command.

As to the errors in log, Jaybird can cause them only after loading the library, which is not the case here - please ensure that this is caused by your Java code.

firebird-automations commented 16 years ago

Commented by: Arjen Markus (arjenmarkus)

To check that the libfbembed.so can be loaded I wrote a small C program that does nothing but load the library. This failed in a first try because the ICU libraries were missing, but after copying those into the directory also containing libfbembed.so it worked.

LD_LIBRARY_PATH is explicitly set to the directory holding all the shared objects and jar files used by the program plus the original value, in a small shell script. What I do not know for sure is the effect of the java runtime option -Djava.library.path which is also used, but I am pretty sure that simply does the same thing all over ;).

Given that the log messages about the connection are stored in a file called "firebird.log" I assume that libfbembed.so is loaded and is trying to do something. The log messages are definitely written by this version of the program, given the timestamp (they are not left-overs).

I wll try to find out where the error messages are coming from.

firebird-automations commented 16 years ago

Commented by: Arjen Markus (arjenmarkus)

The text from the error messages can be found in the library libfbembed.so. I strongly suspected therefore that during the initialisation of Firebird some error occurs. This then causes Jaybird to fail. So, it is not Jaybird that writes these messages, it is Firebird itself.

However, I have no idea what Firebird wants to connect to (as apparently it is trying to connect to something) or why that would fail.

firebird-automations commented 16 years ago

Commented by: Roman Rokytskyy (rrokytskyy)

Yes, this is Firebird Embedded writing messages. The Embedded version can act as a proxy to a "normal" Firebird Server, so, if your Java code tries to connect to remote database (jdbc:firebirdsql:embedded:<host>[/<port>]:db as URL), it might work and would be an explanation for the unresolved host name.

However, the exception stack trace comes from the driver initialization when Jaybird already loaded the JNI proxy (libjaybird21.so) and told the proxy to load the embedded library (libfbembed.so). At that moment no connection can be made - the proxy does not have the entry points in the library resolved.

Sorry, this looks very specific to your environment, since Jaybird + FB Embedded is tested on my Gentoo VM box before release. In order to help you, I need access to your environment (I can give you my public SSH2 key, contact me privately if that is ok). We can also continue in Firebird-Java group (http://groups.yahoo.com/group/Firebird-Java), this is where all problems are usually discussed before it goes into bug tracker.

I will close this issue as "not reproducible", but if we find the reason and it happens bug in Jaybird - we will reopen it again.

firebird-automations commented 16 years ago
Modified by: Roman Rokytskyy (rrokytskyy) status: Open \[ 1 \] =\> Resolved \[ 5 \] resolution: Cannot Reproduce \[ 5 \]
firebird-automations commented 16 years ago
Modified by: Roman Rokytskyy (rrokytskyy) status: Resolved \[ 5 \] =\> Closed \[ 6 \]
firebird-automations commented 16 years ago

Commented by: Arjen Markus (arjenmarkus)

We have made some progress: - The network connection errors were most probably due to us running on a network disk. - If we run locally, a database _is_ created. I can examine it with the isql utility. - However, the program still produces the very same error message and stack trace

As the exception is thrown somewhere in libjaybird.so (or at least that is where the text is coming from) or libfbembed.so, I have no clue as to what the cause is.

(Sorry to add yet another comment, I tried getting an account on Yahoo, but seem unable to connect)

firebird-automations commented 16 years ago

Commented by: Arjen Markus (arjenmarkus)

Solved!

The issue was caused by a combination of two things: 1. Our application is rather picky on things being written to standard error: it considers any output to that channel to be an indication of a problem. 2. Jaybird, the layer on top of Firebird, tries to load two libraries at start-up, one the Windows DLL and the other the Linux shared object. On Linux the first will fail and messages about this are written to standard error. The second will succeed and therefore the installation is okay.

Because of the first item the application complains and stops. I suppose the Jaybird layer could be made more aware of the environment it is running under and try the most likely candidate first.

Anyway, this issue seems to be out of the way now.