Skip to content

Commit 62f3bc2

Browse files
committed
[AMQ-9820]: More reliable fix to avoid stale connections to remain in the pool. And better pool handling on start exception
1 parent 8ea0b88 commit 62f3bc2

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public void start() throws JMSException {
125125
connection.start();
126126
} catch (JMSException e) {
127127
started.set(false);
128+
setHasExpired(true);
128129
if (isReconnectOnException()) {
129130
close();
130131
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,15 @@ public void close() throws JMSException {
9292
@Override
9393
public void start() throws JMSException {
9494
assertNotClosed();
95-
pool.start();
95+
try {
96+
pool.start();
97+
} catch (JMSException e) {
98+
try {
99+
close();
100+
} catch (JMSException ignored) {
101+
}
102+
throw e;
103+
}
96104
}
97105

98106
@Override

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,7 @@ 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.getConnection() == null) {
133-
LOG.trace("Connection has been closed and will be destroyed: {}", connection);
134-
return false;
135-
}
136-
137-
if (connection.expiredCheck()) {
132+
if (connection != null && connection.expiredCheck()) {
138133
LOG.trace("Connection has expired: {} and will be destroyed", connection);
139134
return false;
140135
}

0 commit comments

Comments
 (0)