From c72b226bfb74a4a3895f6d19d41da3486c53fccb Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Fri, 29 May 2020 18:17:11 +0200 Subject: [PATCH] ARTEMIS-2785 io.netty.util.internal.OutOfDirectMemoryError during uncompress --- .../org/apache/activemq/artemis/utils/ByteUtil.java | 11 ----------- .../artemis/core/client/impl/ClientConsumerImpl.java | 7 +++---- .../artemis/core/message/impl/CoreMessage.java | 7 ++++--- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java index 59f5ce1346..84264d3919 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java @@ -239,17 +239,6 @@ public class ByteUtil { return sb.toString(); } - public static byte[] getActiveArray(ByteBuffer buffer) { - byte[] ret = new byte[buffer.remaining()]; - if (buffer.hasArray()) { - byte[] array = buffer.array(); - System.arraycopy(array, buffer.arrayOffset() + buffer.position(), ret, 0, ret.length); - } else { - buffer.slice().get(ret); - } - return ret; - } - public static long convertTextBytes(final String text) { try { Matcher m = ONE.matcher(text); diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java index 7f9ede3cf6..83ee890a81 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/client/impl/ClientConsumerImpl.java @@ -39,7 +39,6 @@ import org.apache.activemq.artemis.core.client.ActiveMQClientLogger; import org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle; import org.apache.activemq.artemis.spi.core.remoting.ConsumerContext; import org.apache.activemq.artemis.spi.core.remoting.SessionContext; -import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.FutureLatch; import org.apache.activemq.artemis.utils.ReusableLatch; import org.apache.activemq.artemis.utils.TokenBucketLimiter; @@ -655,9 +654,9 @@ public final class ClientConsumerImpl implements ClientConsumerInternal { //sets the packet ActiveMQBuffer qbuff = clMessage.toCore().getBodyBuffer(); - int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex(); - final byte[] body = ByteUtil.getActiveArray(qbuff.readBytes(bytesToRead).toByteBuffer()); - + final int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex(); + final byte[] body = new byte[bytesToRead]; + qbuff.readBytes(body); largeMessage.setLargeMessageController(new CompressedLargeMessageControllerImpl(currentLargeMessageController)); currentLargeMessageController.addPacket(body, body.length, false); diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java index 86ca28ad39..7ad2c6becd 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/message/impl/CoreMessage.java @@ -44,7 +44,6 @@ import org.apache.activemq.artemis.core.persistence.CoreMessageObjectPools; import org.apache.activemq.artemis.core.persistence.Persister; import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl; import org.apache.activemq.artemis.reader.MessageUtil; -import org.apache.activemq.artemis.utils.ByteUtil; import org.apache.activemq.artemis.utils.DataConstants; import org.apache.activemq.artemis.utils.UUID; import org.apache.activemq.artemis.utils.collections.TypedProperties; @@ -251,9 +250,11 @@ public class CoreMessage extends RefCountMessage implements ICoreMessage { } private ActiveMQBuffer inflate(ActiveMQBuffer buffer) throws DataFormatException { - int bytesToRead = buffer.readableBytes(); + final int bytesToRead = buffer.readableBytes(); Inflater inflater = new Inflater(); - inflater.setInput(ByteUtil.getActiveArray(buffer.readBytes(bytesToRead).toByteBuffer())); + final byte[] input = new byte[bytesToRead]; + buffer.readBytes(input); + inflater.setInput(input); //get the real size of large message long sizeBody = getLongProperty(Message.HDR_LARGE_BODY_SIZE);