javaoracle-databaseconnectionrecover

java.sql.SQLException: Io exception: Broken pipe how to recover without restart?


In my application I use connection to Oracle, when connection lost and I try to re-connect I receive exception:

java.sql.SQLException: Io exception: Broken pipe
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:161)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:273)
    at oracle.jdbc.driver.T4CStatement.fetch(T4CStatement.java:540)
    at oracle.jdbc.driver.OracleResultSetImpl.close_or_fetch_from_next(OracleResultSetImpl.java:264)
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:196)

For recover I need to restart application, does it possible recover without restart? Thanks.


Solution

  • Followings could be the possibilities which could be causing the exception:

    1. Network problem: That is the network between the database and application server causing the physical connection to be dropped after a period of time. It's probably due to a firewall running behind the network which is configured to kill db connections after a specified period of time. You may consider a workaround to maintain the connection alive all the time simply by re-configuring your application server. For Tomcat, you may try adding validationQuery="select 'validationQuery' from dual in the Tomcat datasource conf file (context.xml)

    2. The connections to the database server are being reset and the client is not notified by the database driver. The problem in this case is that the Oracle driver is discovering that it's socket to the DBMS somehow (firewall again, maybe?) has been closed by the other end. You may consider setting your connection timeout (in the pool) shorter than the network/DB server timeout as a solution.