From e901d2fd2e9afe7a175231ec30aa4c8781762c23 Mon Sep 17 00:00:00 2001 From: Gary Tully Date: Fri, 27 Jan 2012 12:53:09 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-3684 - Potential deadlock in vm transport setListener when sender is blocked pending space Deal with the case of blocked producer git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1236664 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/transport/vm/VMTransport.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java index 3e05d4a8d8..1c51205d20 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/vm/VMTransport.java @@ -226,12 +226,20 @@ public class VMTransport implements Transport, Task { public void setTransportListener(TransportListener commandListener) { try { - try { - enqueueValve.turnOff(); + // enqueue can block on blocking queue, preventing turnOff + // so avoid in that case: https://issues.apache.org/jira/browse/AMQ-3684 + if (async && getMessageQueue().remainingCapacity() == 0) { + // enqueue blocked or will be this.transportListener = commandListener; wakeup(); - } finally { - enqueueValve.turnOn(); + } else { + try { + enqueueValve.turnOff(); + this.transportListener = commandListener; + wakeup(); + } finally { + enqueueValve.turnOn(); + } } } catch (InterruptedException e) { throw new RuntimeException(e);