threads/85112: Resource temporarily unavailable reading from
sockets with Java/libpthread/jdbc
Nick Johnson
freebsd at spatula.net
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
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Aug 19 05:10:08 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator: Nick Johnson
>Release: FreeBSD 5.4-STABLE i386
>Organization:
morons.org
>Environment:
System: FreeBSD turing.morons.org 5.4-STABLE FreeBSD 5.4-STABLE #4: Mon Aug 15 21:22:19 PDT 2005 root at turing.morons.org:/usr/src/sys/i386/compile/TURING 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
>Description:
When attempting to get a database connection with Java linked to libpthread, a socket exception is thrown:
java.net.SocketException: Resource temporarily unavailable
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
at org.postgresql.PG_Stream.ReceiveChar(PG_Stream.java:139)
at org.postgresql.jdbc1.AbstractJdbc1Connection.openConnection(AbstractJdbc1Connection.java:190)
at org.postgresql.Driver.connect(Driver.java:122)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
at net.spatula.news.Utils.getJDBCconnection(Utils.java:816)
Here is the code from getJDBCconnection, verbatim, including ugliness just for fun...
public static synchronized Connection getJDBCconnection() {
try {
Class.forName("org.postgresql.Driver");
} catch (Exception e) {
e.printStackTrace();
}
int retryCount = 5;
while (retryCount >0) {
try {
//XXX database name and username should be properties
String dbURL = "jdbc:postgresql://"+ getProperty("spatula.dbhost")+":"+
getProperty("spatula.dbport")+"/morons.org?user=www&password="+
getProperty("spatula.dbpass");
Connection c = DriverManager.getConnection(dbURL); // <--- this is line 816
return c;
} catch (Exception e) {
e.printStackTrace();
}
retryCount--;
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:
CPUTYPE?=i686
CFLAGS=-O2 -pipe
or it may be totally unrelated. See also threads/84778 (http://www.freebsd.org/cgi/query-pr.cgi?pr=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.)
>How-To-Repeat:
Try to get a database connection.
>Fix:
Workaround is to configure the linker to use libc_r for all Java processes
in /etc/libmap.conf:
[/usr/local/jdk1.4.2/]
libpthread.so.1 libc_r.so.5
libpthread.so libc_r.so
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-threads
mailing list