This is an automated email from the ASF dual-hosted git repository.

jbertram pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 6700541d46 ARTEMIS-5735 avoid race b/w session creation & connection 
failure
6700541d46 is described below

commit 6700541d4604e2602551c8c64dac7d923fcbe165
Author: michaeladada <[email protected]>
AuthorDate: Fri Dec 5 18:26:06 2025 +0200

    ARTEMIS-5735 avoid race b/w session creation & connection failure
---
 .../artemis/core/protocol/openwire/OpenWireConnection.java     | 10 ++++++++--
 .../activemq/artemis/core/server/impl/ActiveMQServerImpl.java  |  4 ++++
 .../activemq/artemis/core/server/impl/ServerSessionImpl.java   |  1 -
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git 
a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
 
b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
index 5f329426d2..e414d022b2 100644
--- 
a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
+++ 
b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireConnection.java
@@ -1224,6 +1224,14 @@ public class OpenWireConnection extends 
AbstractRemotingConnection implements Se
                   return null;
                }
             }
+
+            // In certain circumstances (e.g. JCA use-cases with the ActiveMQ 
RA) an OpenWire client can "clean up" a
+            // connection by sending a RemoveInfo command (which will 
"destroy" this broker-side connection) followed
+            // shortly by a ConnectionInfo command. In order to deal with this 
we "undestroy" the broker-side connection
+            // here. If we do not "undestroy" the connection here then 
creating the internal Core session will fail.
+            // See 
org.apache.activemq.ConnectionCleanupTest#testChangeClientID for a test that 
executes this scenario.
+            destroyed = false;
+
             protocolManager.addConnection(OpenWireConnection.this, info);
          } catch (Exception e) {
             Response resp = new ExceptionResponse(e);
@@ -1238,8 +1246,6 @@ public class OpenWireConnection extends 
AbstractRemotingConnection implements Se
             }
             dispatchAsync(command);
          }
-         // During a chanceClientID a disconnect could have been sent by the 
client, and the client will then re-issue a connect packet
-         destroyed = false;
          return null;
 
       }
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index 4fa48902dc..cbea15b803 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -1926,6 +1926,10 @@ public class ActiveMQServerImpl implements 
ActiveMQServer {
 
       sessions.put(name, session);
       totalSessionCount.incrementAndGet();
+      connection.addFailureListener(session);
+      if (connection.isDestroyed()) {
+         session.close(true);
+      }
 
       if (hasBrokerSessionPlugins()) {
          callBrokerSessionPlugins(plugin -> 
plugin.afterCreateSession(session));
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
index b6ffaea8b3..04b3c49620 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
@@ -286,7 +286,6 @@ public class ServerSessionImpl extends 
CriticalComponentImpl implements ServerSe
 
       this.defaultAddress = defaultAddress;
 
-      remotingConnection.addFailureListener(this);
       this.context = context;
 
       this.sessionExecutor = server.getExecutorFactory().getExecutor();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to