Skip to content

Commit 653f4db

Browse files
committed
Attempt to better handle cases where underlying connection is closed tue to reconnectOnException flag
1 parent 3565659 commit 653f4db

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnectionFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ public void destroyObject(ConnectionKey connectionKey, PooledObject<ConnectionPo
129129
@Override
130130
public boolean validateObject(ConnectionKey connectionKey, PooledObject<ConnectionPool> pooledObject) {
131131
ConnectionPool connection = pooledObject.getObject();
132-
if (connection != null && connection.expiredCheck()) {
132+
if (connection == null || connection.getConnection() == null) {
133+
LOG.trace("Connection has been closed and will be destroyed: {}", connection);
134+
return false;
135+
}
136+
137+
if (connection.expiredCheck()) {
133138
LOG.trace("Connection has expired: {} and will be destroyed", connection);
134139
return false;
135140
}

activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionSecurityExceptionTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,12 @@ public void testFailoverWithInvalidCredentials() throws Exception {
237237

238238
@Override
239239
public boolean isSatisified() throws Exception {
240-
return connection1.getConnection() !=
241-
((PooledConnection) pooledConnFact.createConnection("invalid", "credentials")).getConnection();
240+
PooledConnection newConnection = (PooledConnection) pooledConnFact.createConnection("invalid", "credentials");
241+
try {
242+
return connection1.getConnection() != newConnection.getConnection();
243+
} finally {
244+
newConnection.close();
245+
}
242246
}
243247
}));
244248

0 commit comments

Comments
 (0)