Skip to content

Commit 86c4c55

Browse files
committed
Fix race condition in async exception handling by combining JMS ExceptionListener and TransportListener notifications
1 parent 7d5291e commit 86c4c55

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,8 +2046,21 @@ public void onAsyncException(Throwable error) {
20462046

20472047
@Override
20482048
public void onException(final IOException error) {
2049-
onAsyncException(error);
2049+
// Combine JMS ExceptionListener and TransportListener notifications
2050+
// into a single async task to prevent a race condition where the
2051+
// ExceptionListener (e.g. ConnectionPool) closes the connection and
2052+
// shuts down the executor before the TransportListener task is queued.
20502053
executeAsync(() -> {
2054+
// Notify JMS ExceptionListener first (same as onAsyncException)
2055+
if (exceptionListener != null) {
2056+
try {
2057+
final JMSException jmsError = JMSExceptionSupport.create(error);
2058+
exceptionListener.onException(jmsError);
2059+
} catch (final Exception e) {
2060+
LOG.debug("Exception during JMS ExceptionListener notification", e);
2061+
}
2062+
}
2063+
20512064
transportFailed(error);
20522065
ServiceSupport.dispose(ActiveMQConnection.this.transport);
20532066
brokerInfoReceived.countDown();

0 commit comments

Comments
 (0)