You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/09/07 14:40:35 UTC

[2/2] activemq-artemis git commit: ARTEMIS-1401 Numerical overflow fix when using System::nanoTime

ARTEMIS-1401 Numerical overflow fix when using System::nanoTime


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/35c34750
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/35c34750
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/35c34750

Branch: refs/heads/master
Commit: 35c3475092576e7b008220f7c39b78e15850d5fd
Parents: 65a0c61
Author: Francesco Nigro <ni...@gmail.com>
Authored: Thu Sep 7 12:25:45 2017 +0200
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Sep 7 10:40:14 2017 -0400

----------------------------------------------------------------------
 .../activemq/artemis/core/remoting/impl/netty/NettyConnection.java | 2 +-
 .../org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java    | 2 +-
 .../artemis/tests/unit/core/journal/impl/TimedBufferTest.java      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/35c34750/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
----------------------------------------------------------------------
diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
index 10dc553..3d141a7 100644
--- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
+++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyConnection.java
@@ -330,7 +330,7 @@ public class NettyConnection implements Connection {
             parkNanos = 1000L;
          }
          boolean canWrite;
-         while (!(canWrite = canWrite(requiredCapacity)) && System.nanoTime() < deadline) {
+         while (!(canWrite = canWrite(requiredCapacity)) && (System.nanoTime() - deadline) < 0) {
             //periodically check the connection state
             checkConnectionState();
             LockSupport.parkNanos(parkNanos);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/35c34750/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java
----------------------------------------------------------------------
diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java
index 6ed3e7b..0015dc5 100644
--- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java
+++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/buffer/TimedBuffer.java
@@ -386,7 +386,7 @@ public final class TimedBuffer {
                   lastFlushTime = System.nanoTime();
                   flush();
 
-               } else if (bufferObserver != null && System.nanoTime() > lastFlushTime + timeout) {
+               } else if (bufferObserver != null && System.nanoTime() - lastFlushTime > timeout) {
                   lastFlushTime = System.nanoTime();
                   // if not using flush we will spin and do the time checks manually
                   flush();

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/35c34750/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java
----------------------------------------------------------------------
diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java
index 87a1439..2462ee7 100644
--- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java
+++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/TimedBufferTest.java
@@ -227,7 +227,7 @@ public class TimedBufferTest extends ActiveMQTestBase {
    private static void spinSleep(long timeout) {
       if (timeout > 0) {
          final long deadline = System.nanoTime() + timeout;
-         while (System.nanoTime() < deadline) {
+         while (System.nanoTime() - deadline < 0) {
             //spin wait
          }
       }