From 0f952f72f798c5626dcd6270c9282e0e8988bd41 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Wed, 2 Jun 2021 09:47:24 -0400 Subject: [PATCH] AMQ-8287 - fix NIOSSLTransport deadlock with serviceRead lock This narrows the lock that was added to serviceRead() to secureRead() which prevents processing commands while locked which should solve the deadlock issues (cherry picked from commit 2fcf2fd75f7c2a04151a2284595a08bf4c03240b) --- .../activemq/transport/nio/AutoInitNioSSLTransport.java | 3 +-- .../org/apache/activemq/transport/nio/NIOSSLTransport.java | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java b/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java index 98d0d79f86..e5717ac650 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java +++ b/activemq-broker/src/main/java/org/apache/activemq/transport/nio/AutoInitNioSSLTransport.java @@ -158,9 +158,8 @@ public class AutoInitNioSSLTransport extends NIOSSLTransport { return readSize; } - //Prevent concurrent access to SSLEngine @Override - public synchronized void serviceRead() { + public void serviceRead() { try { if (handshakeInProgress) { doHandshake(); diff --git a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java index 4c944f494a..d0e2fc8e09 100644 --- a/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java +++ b/activemq-client/src/main/java/org/apache/activemq/transport/nio/NIOSSLTransport.java @@ -243,9 +243,8 @@ public class NIOSSLTransport extends NIOTransport { } } - //Prevent concurrent access to SSLEngine @Override - public synchronized void serviceRead() { + public void serviceRead() { try { if (handshakeInProgress) { doHandshake(); @@ -374,7 +373,8 @@ public class NIOSSLTransport extends NIOTransport { } } - protected int secureRead(ByteBuffer plain) throws Exception { + //Prevent concurrent access while reading from the channel + protected synchronized int secureRead(ByteBuffer plain) throws Exception { if (!(inputBuffer.position() != 0 && inputBuffer.hasRemaining()) || status == SSLEngineResult.Status.BUFFER_UNDERFLOW) { int bytesRead = channel.read(inputBuffer);