Skip to content

AMQ-9693: avoid synchronized blocks #1420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jeanouii
Copy link

@jeanouii jeanouii commented Apr 14, 2025

This PR fixes a couple of issues in the RA.

  • move the running flag to a non-blocking approach (remove synchronized on a mutex and use AtomicBoolean)
  • update the running to false if we can shedule a task in the worker
  • move the listener initialization to the #start which is functionally better and avoid stacking messages in the session while it's not started
  • avoid pulling a stale (or not running) session from the pool if we can find otherwise

@jbonofre jbonofre self-requested a review April 14, 2025 21:15
@@ -64,8 +65,8 @@ public class ServerSessionImpl implements ServerSession, InboundContext, Work, D
private MessageProducer messageProducer;
private final ServerSessionPoolImpl pool;

private Object runControlMutex = new Object();
private boolean runningFlag;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the problem is here as the runningFlag is not thread safe (and we can have several session), right ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a trick, because this avoids the lock but does not fix yet the initial issue in my opinion. There is an underlying bug revealed by this deadlock allowing another thread to be using this session to dispatch unconsumed messages from a stale session (removeFromPool).

Trying to properly understand it, so I can push a more complete fix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the trick can happen when there is no more session in the pool, then ActiveMQ pulls an active session leading to a deadlock as I have observed. With the AtomicInterger, the integrity is preserved without any locks.

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.

2 participants