From 198143edd082325801cbe8b1d8aa885a3ad47f35 Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Fri, 16 Dec 2016 12:11:40 +0000 Subject: [PATCH] ARTEMIS-892 - add lock to tick method https://issues.apache.org/jira/browse/ARTEMIS-892 --- .../amqp/proton/handler/ProtonHandler.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java index 945d01ebf7..71cf4a3ead 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/handler/ProtonHandler.java @@ -91,22 +91,24 @@ public class ProtonHandler extends ProtonInitializable { } public long tick(boolean firstTick) { - if (!firstTick) { - try { - if (connection.getLocalState() != EndpointState.CLOSED) { - long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); - if (transport.isClosed()) { - throw new IllegalStateException("Channel was inactive for to long"); + synchronized (lock) { + if (!firstTick) { + try { + if (connection.getLocalState() != EndpointState.CLOSED) { + long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); + if (transport.isClosed()) { + throw new IllegalStateException("Channel was inactive for to long"); + } + return rescheduleAt; } - return rescheduleAt; + } catch (Exception e) { + transport.close(); + connection.setCondition(new ErrorCondition()); } - } catch (Exception e) { - transport.close(); - connection.setCondition(new ErrorCondition()); + return 0; } - return 0; + return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); } - return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); } public int capacity() {