threads/85112: Resource temporarily unavailable reading from sockets with Java/libpthread/jdbc

Nick Johnson freebsd at
Fri Aug 19 05:10:12 GMT 2005

>Number:         85112
>Category:       threads
>Synopsis:       Resource temporarily unavailable reading from sockets with Java/libpthread/jdbc
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-threads
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 19 05:10:08 GMT 2005
>Originator:     Nick Johnson
>Release:        FreeBSD 5.4-STABLE i386
System: FreeBSD 5.4-STABLE FreeBSD 5.4-STABLE #4: Mon Aug 15 21:22:19 PDT 2005 root at i386

Java 1.4.2-p7 built from ports
Postgresql 8.0.3 built from ports; however still using the Postgresql 7.4 JDBC driver

When attempting to get a database connection with Java linked to libpthread, a socket exception is thrown: Resource temporarily unavailable
        at Method)
        at org.postgresql.PG_Stream.ReceiveChar(
        at org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(
        at org.postgresql.Driver.connect(
        at java.sql.DriverManager.getConnection(
        at java.sql.DriverManager.getConnection(

Here is the code from getJDBCconnection, verbatim, including ugliness just for fun...

    public static synchronized Connection getJDBCconnection() {
        try {
        } catch (Exception e) {
        int retryCount = 5;
        while (retryCount >0) {
            try {
                //XXX database name and username should be properties
                String dbURL = "jdbc:postgresql://"+ getProperty("spatula.dbhost")+":"+
                Connection c = DriverManager.getConnection(dbURL);  // <--- this is line 816
                return c;
            } catch (Exception e) {
            try {
                Thread.sleep(200 + (int)(Math.random()*50.0));
            } catch (Exception e) {}
        return null;

This fails every time when java links against libpthread and works every time when it is linked against libc_r.

I'm not entirely sure, but this may have started showing itself after I added this to /etc/make.conf:

	CFLAGS=-O2 -pipe

or it may be totally unrelated.  See also threads/84778 ( which was previously
preventing me from getting far enough to make a database connection.  (Once the class files were compiled with a process
linked against libc_r, they were in place for a process linked against libpthread to use.)


Try to get a database connection.

Workaround is to configure the linker to use libc_r for all Java processes
in /etc/libmap.conf:




More information about the freebsd-threads mailing list