Skip to content

Conversation

@michaeladada
Copy link
Contributor

  • By adding the session to connection failure listener only after it was registered
  • And closing the session if the connection was destroyed in the meantime

@clebertsuconic
Copy link
Contributor

do you have a test for this condition?

@michaeladada
Copy link
Contributor Author

michaeladada commented Nov 13, 2025

do you have a test for this condition?

Since this is a race condition, there is no easy way to test it completely.
Or do you mean specifically the part of closing of the session in case the connection is already destroyed?

@jbertram
Copy link
Contributor

Static analysis might be sufficient for this.

- add the session to connection failure listener only after it was registered
- close the session if the connection was destroyed in the meantime
@jbertram jbertram changed the title ARTEMIS-5735 : Avoid race condition of session creation and connection failure ARTEMIS-5735 avoid race b/w session creation & connection failure Nov 13, 2025
@tabish121
Copy link
Contributor

LGTM

@gemmellr
Copy link
Member

There looks to be a persistent test failure introduced in one of the extra ported OpenWire tests. On 3 full runs org.apache.activemq.ConnectionCleanupTest.testChangeClientID() has failed each time, complaining about a session being closed whilst creating a consumer.

It does look like a strange test, accessing client internals to 'remove' and yet then reuse the same Connection, so I'm not clear whether its something real clients and applications can do and if so whether it needs to be kept working.

@jbertram
Copy link
Contributor

For what it's worth, this fixes the test:

diff --git a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ConnectionCleanupTest.java b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ConnectionCleanupTest.java
index 2e4a2e05a0..07421e69f4 100644
--- a/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ConnectionCleanupTest.java
+++ b/tests/activemq5-unit-tests/src/test/java/org/apache/activemq/ConnectionCleanupTest.java
@@ -48,6 +48,7 @@ public class ConnectionCleanupTest extends TestCase {
       }
 
       connection.doCleanup(true);
+      connection.setWatchTopicAdvisories(false);
       connection.setClientID("test");
 
       connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

@jbertram
Copy link
Contributor

I believe I've found the underlying problem. I'll push a separate commit to this branch to fix it and allow review.

@jbertram
Copy link
Contributor

FYI - commit was pushed.

@jbertram
Copy link
Contributor

The full test-suite looks good on this.

@tabish121
Copy link
Contributor

I've run this through CI a few times and the previous failures are gone. One thing I'm not sure of is that the test runs with this branch are running consistently longer but I can't see how this change would have caused that. Probably safe to squash the commits now.

@gemmellr
Copy link
Member

gemmellr commented Dec 5, 2025

It is 30 commits behind main, and Clebert did add a really slow test and tweak it later..could be it has the former change but is missing the later one.

@jbertram
Copy link
Contributor

jbertram commented Dec 5, 2025

Can we leave the commits separate since they are from 2 different authors and both are non-trivial (in my opinion)?

@tabish121
Copy link
Contributor

It is 30 commits behind main, and Clebert did add a really slow test and tweak it later..could be it has the former change but is missing the later one.

I figured that was likely the reasons.

@tabish121
Copy link
Contributor

tabish121 commented Dec 5, 2025

Can we leave the commits separate since they are from 2 different authors and both are non-trivial (in my opinion)?

We could but it means you have a known breaking commit that requires the fix that follows.

@jbertram
Copy link
Contributor

jbertram commented Dec 5, 2025

Both are correlated with ARTEMIS-5735 so that should be pretty straight-forward, I think.

@gemmellr
Copy link
Member

gemmellr commented Dec 5, 2025

I would squash during 'merge' personally, its really 1 overall change, would be nicer if it was all in the same commit, and its nice not adding known-broken stuff to main. Can always still see both component commits on the PR later if looking at the change close enough to care.

@jbertram jbertram merged commit 6700541 into apache:main Dec 5, 2025
6 checks passed
@jbertram
Copy link
Contributor

jbertram commented Dec 5, 2025

Squashed & merged. Thanks for the review!

@jbertram
Copy link
Contributor

jbertram commented Dec 5, 2025

@michaeladada, thanks for the contribution. Nice work!

@michaeladada
Copy link
Contributor Author

@michaeladada, thanks for the contribution. Nice work!

@jbertram , thank you and everyone else involved for taking it from the PR and making the entire process so smooth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants