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 2021/03/24 13:07:53 UTC

[activemq-artemis] branch master updated: ARTEMIS-3045 NettyConnection should null-check Netty buffer

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 7bd2a4d  ARTEMIS-3045 NettyConnection should null-check Netty buffer
7bd2a4d is described below

commit 7bd2a4d08061bf0fc4218a8c3ec4d21c58a1ebf3
Author: franz1981 <ni...@gmail.com>
AuthorDate: Tue Mar 23 21:35:53 2021 +0100

    ARTEMIS-3045 NettyConnection should null-check Netty buffer
---
 .../artemis/core/remoting/impl/netty/NettyConnection.java   | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

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 431834e..75c092e 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
@@ -27,6 +27,7 @@ import io.netty.buffer.ByteBuf;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelOutboundBuffer;
 import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.util.concurrent.FastThreadLocal;
@@ -99,7 +100,11 @@ public class NettyConnection implements Connection {
     * Returns an estimation of the current size of the write buffer in the channel.
     */
    private static long batchBufferSize(Channel channel) {
-      return channel.unsafe().outboundBuffer().totalPendingWriteBytes();
+      final ChannelOutboundBuffer outboundBuffer = channel.unsafe().outboundBuffer();
+      if (outboundBuffer == null) {
+         return 0;
+      }
+      return outboundBuffer.totalPendingWriteBytes();
    }
 
    public final Channel getNettyChannel() {
@@ -248,10 +253,10 @@ public class NettyConnection implements Connection {
    // This is called periodically to flush the batch buffer
    @Override
    public final void checkFlushBatchBuffer() {
-      if (this.batchingEnabled) {
+      if (batchingEnabled) {
          // perform the flush only if necessary
-         if (batchBufferSize(this.channel) > 0 && !channel.isWritable()) {
-            this.channel.flush();
+         if (batchBufferSize(channel) > 0) {
+            channel.flush();
          }
       }
    }