[
https://issues.apache.org/jira/browse/ARTEMIS-5874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18055657#comment-18055657
]
Justin Bertram commented on ARTEMIS-5874:
-----------------------------------------
Looking at the latest code I believe the dead-lock is still possible, and I
think it could be avoided by removing {{failLock}} completely and turning
{{destroyed}} into an {{AtomicBoolean}}, e.g.:
{noformat}
diff --git
a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
index f353afef03a..c57756c410c 100644
---
a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
+++
b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
@@ -28,6 +28,7 @@ import java.util.StringTokenizer;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicBoolean;
import
org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
@@ -81,12 +82,10 @@ public final class StompConnection extends
AbstractRemotingConnection {
//this means login is valid. (stomp connection ok)
private boolean valid;
- private boolean destroyed = false;
+ private AtomicBoolean destroyed = new AtomicBoolean(false);
private final Acceptor acceptorUsed;
- private final Object failLock = new Object();
-
private final boolean enableMessageID;
private final int minLargeMessageSize;
@@ -224,15 +223,9 @@ public final class StompConnection extends
AbstractRemotingConnection {
@Override
public void destroy() {
- synchronized (failLock) {
- if (destroyed) {
- return;
- }
-
- destroyed = true;
+ if (destroyed.compareAndSet(false, true)) {
+ internalClose();
}
-
- internalClose();
}
public Acceptor getAcceptorUsed() {
@@ -255,24 +248,17 @@ public final class StompConnection extends
AbstractRemotingConnection {
@Override
public void fail(final ActiveMQException me) {
- synchronized (failLock) {
- if (destroyed) {
- return;
- }
-
+ if (destroyed.compareAndSet(false, true)) {
StompFrame frame =
frameHandler.createStompFrame(Stomp.Responses.ERROR);
frame.addHeader(Stomp.Headers.Error.MESSAGE, me.getMessage());
sendFrame(frame, null);
+
ActiveMQServerLogger.LOGGER.connectionFailureDetected(me.getMessage(),
me.getType());
- destroyed = true;
- }
-
- ActiveMQServerLogger.LOGGER.connectionFailureDetected(me.getMessage(),
me.getType());
+ // Then call the listeners
+ callFailureListeners(me);
- // Then call the listeners
- callFailureListeners(me);
-
- internalClose();
+ internalClose();
+ }
}
@Override{noformat}
> Deadlock in STOMP protocol on DISCONNECT with receipt
> -----------------------------------------------------
>
> Key: ARTEMIS-5874
> URL: https://issues.apache.org/jira/browse/ARTEMIS-5874
> Project: Artemis
> Issue Type: Bug
> Components: STOMP
> Affects Versions: 2.39.0
> Environment: ActiveMQ 2.39.0
> Linux
>
> Reporter: Arthur Naseef
> Assignee: Justin Bertram
> Priority: Critical
> Attachments: FRAME.connect, FRAME.disconnect, STACK.txt
>
>
> STOMP protocol can hit a JVM deadlock. Here are the key details:
> * DISCONNECT frame sent to the broker on valid STOMP connection
> ** with a "receipt" header
> * At the same time, Netty reports a disconnect (call goes to
> {{org.apache.activemq.artemis.core.remoting.server.impl.RemotingServiceImpl.connectionException}})
> Deadlock is reported by {{jstack}} or {{jcmd ... Thread.print.}}
> The cause is 2 locks being acquired in different orders by separate threads.
> Here are the top of the calling stack for the 2 deadlocked threads:
> * at
> org.apache.activemq.artemis.core.protocol.stomp.StompProtocolManager.send(StompProtocolManager.java:203)
> * at
> org.apache.activemq.artemis.core.protocol.stomp.StompConnection.destroy(StompConnection.java:225)
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]