You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2017/07/17 20:29:05 UTC

qpid-jms git commit: QPIDJMS-301 Release buffer reference when send on not connected

Repository: qpid-jms
Updated Branches:
  refs/heads/master e447924a4 -> e249763c0


QPIDJMS-301 Release buffer reference when send on not connected

If not connected the send call will throw and it needs to release the
reference that exists on the buffer if it came from a buffer pool.

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e249763c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e249763c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e249763c

Branch: refs/heads/master
Commit: e249763c00594d73abe7809f7f776dba148d225c
Parents: e447924
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Jul 17 16:28:55 2017 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Jul 17 16:28:55 2017 -0400

----------------------------------------------------------------------
 .../jms/transports/netty/NettyTcpTransport.java | 11 ++++-
 .../transports/netty/NettyTcpTransportTest.java | 42 ++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e249763c/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
index 1f17069..da77be8 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/transports/netty/NettyTcpTransport.java
@@ -54,6 +54,7 @@ import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioSocketChannel;
 import io.netty.handler.logging.LoggingHandler;
 import io.netty.handler.ssl.SslHandler;
+import io.netty.util.ReferenceCountUtil;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
 
@@ -249,7 +250,8 @@ public class NettyTcpTransport implements Transport {
 
     @Override
     public void send(ByteBuf output) throws IOException {
-        checkConnected();
+        checkConnected(output);
+
         int length = output.readableBytes();
         if (length == 0) {
             return;
@@ -372,6 +374,13 @@ public class NettyTcpTransport implements Transport {
         }
     }
 
+    private void checkConnected(ByteBuf output) throws IOException {
+        if (!connected.get()) {
+            ReferenceCountUtil.release(output);
+            throw new IOException("Cannot send to a non-connected transport.");
+        }
+    }
+
     /*
      * Called when the transport has successfully connected and is ready for use.
      */

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e249763c/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
index 5e8733b..af354b2 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/transports/netty/NettyTcpTransportTest.java
@@ -36,6 +36,7 @@ import org.apache.qpid.jms.test.Wait;
 import org.apache.qpid.jms.transports.Transport;
 import org.apache.qpid.jms.transports.TransportListener;
 import org.apache.qpid.jms.transports.TransportOptions;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,6 +45,8 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.epoll.Epoll;
 import io.netty.channel.epoll.EpollEventLoopGroup;
+import io.netty.util.ResourceLeakDetector;
+import io.netty.util.ResourceLeakDetector.Level;
 
 /**
  * Test basic functionality of the Netty based TCP transport.
@@ -462,6 +465,45 @@ public class NettyTcpTransportTest extends QpidJmsTestCase {
         }
     }
 
+    @Ignore("Used for checking for transport level leaks, my be unstable on CI.")
+    @Test(timeout = 60 * 1000)
+    public void testSendToClosedTransportFailsButDoesNotLeak() throws Exception {
+        Transport transport = null;
+
+        ResourceLeakDetector.setLevel(Level.PARANOID);
+
+        try (NettyEchoServer server = createEchoServer(createServerOptions())) {
+            server.start();
+
+            int port = server.getServerPort();
+            URI serverLocation = new URI("tcp://localhost:" + port);
+
+            for (int i = 0; i < 256; ++i) {
+                transport = createTransport(serverLocation, testListener, createClientOptions());
+                try {
+                    transport.connect(null);
+                    LOG.info("Connected to server:{} as expected.", serverLocation);
+                } catch (Exception e) {
+                    fail("Should have connected to the server at " + serverLocation + " but got exception: " + e);
+                }
+
+                assertTrue(transport.isConnected());
+
+                ByteBuf sendBuffer = transport.allocateSendBuffer(10 * 1024 * 1024);
+
+                transport.close();
+
+                try {
+                    transport.send(sendBuffer);
+                    fail("Should throw on send of closed transport");
+                } catch (IOException ex) {
+                }
+            }
+
+            System.gc();
+        }
+    }
+
     @Test(timeout = 60 * 1000)
     public void testConnectToServerWithEpollEnabled() throws Exception {
         doTestEpollSupport(true);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org