Sunday, December 16, 2012

java.sql.SQLRecoverableException: IO Error: Connection reset and /dev/urandom

Following stack trace could be seen when the application server was starting.
java.sql.SQLRecoverableException: IO Error: Connection reset
        at oracle.jdbc.driver.T4CStatement.executeForDescribe(
        at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(
        at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(
        at oracle.jdbc.driver.OracleStatement.executeQuery(
        at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(
Caused by: Connection reset
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(
        at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(
        at oracle.jdbc.driver.T4CTTIfun.receive(
        at oracle.jdbc.driver.T4CTTIfun.doRPC(
        at oracle.jdbc.driver.T4C8Oall.doOALL(
        at oracle.jdbc.driver.T4CStatement.doOall8(
        at oracle.jdbc.driver.T4CStatement.executeForDescribe(
        ... 6 more
The application servers (6 of them) were running on RHEL 5 (x86_64) and this is a new deployment so there's less activity on the servers. The JDBC drivers were
It seems the JDBC thin clients running on Linux system uses /dev/random for security purposes and the amount of activity (entropy - disorder in the system to be precise) determine how fast /dev/random can deliver random numbers. A good explanation of this is available here. By default JDBC uses /dev/random and could cause JDBC connection creation to hang when the /dev/random cannot generate random numbers fast enough.

One of the solutions (more available on the above mentioned link) is to make JDBC use /dev/urandom which can deliver random numbers with less activity than /dev/random. (According link above these values are "theoretically vulnerable to a cryptographic attack").
JDBC could be made to use /dev/urandom by specifying it as a system property (triple "/" is needed)
For some systems alternate formats of the URL may be needed and these are available in the metalink note given below.

Useful metalink notes
ODI Receives Timeout Messages On Linux x86 With Java 1.5 Onwards [ID 1277360.1]
Oracle Service Registry 11.1 Fails To Install with 'java.sql.SQLRecoverableException: IO Error: Connection reset' Error [ID 1343776.1]