Description
While the adapter is trying to perform a database operation on a connection, a stale connection error occurs and “com.ibm.websphere.ce.cm.StaleConnectionException” is thrown.
Cause
A stale connection situation occurs when an event happens that invalidates the physical connection used for an active database connection that is currently used by an application and the connection is not closed but it throws the
StaleConnectionException.
Example:
A connection is active and used in a transaction and there is a firewall between the application server and database server. If the firewall authentication expires while the application server is not aware of the invalid condition of the connection then the connection is not ready to be used.
Solution
There are two datasource configurations that will prevent the container from providing a stale connection to the adapter application:
1. Pretest Connections
This configuration -if checked- lets the process server test the connections in the pool by performing a test query every period of time, this insures the validity of the connection before delivering it to the requesting application and thus reduces the chance to have a stale connection.
Attachment:
Websphere adapters stale connection.JPG
2. Minimum Number of connections
In the connection pool settings for connection factory of the adapter (not the connection pool of the datasource), ensure that MinimumConnections properties is set to 0. The reason for this property setting is to disable any caching of connections at the adapter connection level. This property tells the server to open new connections when the number of connections in the pool is less than the value of this property. Therefore, setting this property to 0 makes no connections in the pool when no connections are needed. In general, it is a good practice; when you are using datasources, to disable the connection pooling on the adapter level as the datasource already has its own pool, thus, centralize the connection pool management in a single place.
The application developer has the responsibility in solving this problem at the application level -in case the business flow will be affected- by catching the StaleConnectionException and recovering the application from the bad connections.