RabbitMQ Java Client - OutOfMemory on Android for newConnection()

176 views
Skip to first unread message

Attila Rozsa

unread,
Jul 27, 2016, 8:17:20 AM7/27/16
to rabbitmq-users
I'm writing a RMQ Android client application that should connect to CloudAMQP (running RMQ 3.4.2) via the RMQ Java Client (3.6.3).

The factory.newConnection() from below snippet gives OutOfMemory:

ConnectionFactory factory = new ConnectionFactory();
try {
        Log.d(MainActivity.LOG, "MQuri: " + uri);
        factory.setUri(uri);
} catch (Exception e1) {
        Log.d("", "Connection broken: " + e1.getClass().getName() + ": " + e1.getMessage() );
        e1.printStackTrace();
}

factory.setAutomaticRecoveryEnabled(false);
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.basicQos(1);

String MQQueue = MainActivity.getMQQueue(appcontext);
channel.queueDeclare(MQQueue, false, false, false, null);
QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume(MQQueue, false, consumer);

The connection establishment is as follows:
07-27 08:12:26.157: D/remotemonitormq(833): MQuri0
07-27 08:12:27.277: D/dalvikvm(833): GC_FOR_ALLOC freed 379K, 17% free 2637K/3140K, paused 49ms, total 54ms
07-27 08:12:27.577: D/dalvikvm(833): GC_FOR_ALLOC freed 19K, 16% free 2661K/3140K, paused 230ms, total 231ms
07-27 08:12:27.587: I/dalvikvm-heap(833): Forcing collection of SoftReferences for 1345270078-byte allocation
07-27 08:12:27.667: D/dalvikvm(833): GC_BEFORE_OOM freed 70K, 18% free 2590K/3140K, paused 75ms, total 75ms
07-27 08:12:27.667: E/dalvikvm-heap(833): Out of memory on a 1345270078-byte allocation.
07-27 08:12:27.667: I/dalvikvm(833): "AMQP Connection 146.148.23.73:443" prio=5 tid=12 RUNNABLE
07-27 08:12:27.667: I/dalvikvm(833):   | group="main" sCount=0 dsCount=0 obj=0x4173f638 self=0x2a05a0b0
07-27 08:12:27.676: I/dalvikvm(833):   | sysTid=852 nice=0 sched=0/0 cgrp=apps/bg_non_interactive handle=704987552
07-27 08:12:27.676: I/dalvikvm(833):   | state=R schedstat=( 110082952 221999830 27 ) utm=8 stm=3 core=0
07-27 08:12:27.676: I/dalvikvm(833):   at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:~116)
07-27 08:12:27.686: I/dalvikvm(833):   at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
07-27 08:12:27.686: I/dalvikvm(833):   at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:542)
07-27 08:12:27.686: I/dalvikvm(833):   at java.lang.Thread.run(Thread.java:841)
07-27 08:12:27.716: D/(833): Connection broken: java.io.IOException: null
07-27 08:12:27.716: W/System.err(833): java.io.IOException
07-27 08:12:27.737: W/System.err(833): 	at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
07-27 08:12:27.737: W/System.err(833): 	at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
07-27 08:12:27.746: W/System.err(833): 	at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:350)
07-27 08:12:27.746: W/System.err(833): 	at com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory.newConnection(RecoveryAwareAMQConnectionFactory.java:37)
07-27 08:12:27.756: W/System.err(833): 	at com.rabbitmq.client.impl.recovery.AutorecoveringConnection.init(AutorecoveringConnection.java:93)
07-27 08:12:27.756: W/System.err(833): 	at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:805)
07-27 08:12:27.766: W/System.err(833): 	at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:767)
07-27 08:12:27.766: W/System.err(833): 	at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:857)
07-27 08:12:27.776: W/System.err(833): 	at com.atticus.remotemonitormq.MQService$2.run(MQService.java:112)
07-27 08:12:27.776: W/System.err(833): 	at java.lang.Thread.run(Thread.java:841)
07-27 08:12:27.786: W/System.err(833): Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
07-27 08:12:27.786: W/System.err(833): 	at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
07-27 08:12:27.796: W/System.err(833): 	at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:37)
07-27 08:12:27.796: W/System.err(833): 	at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:367)
07-27 08:12:27.806: W/System.err(833): 	at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:293)
07-27 08:12:27.816: W/System.err(833): 	... 7 more
07-27 08:12:27.816: W/System.err(833): Caused by: java.lang.OutOfMemoryError
07-27 08:12:27.836: W/System.err(833): 	at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:116)
07-27 08:12:27.836: W/System.err(833): 	at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
07-27 08:12:27.856: W/System.err(833): 	at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:542)
07-27 08:12:27.856: W/System.err(833): 	... 1 more

Seems like the RMQ java client tries to allocate a lot of memory.
Any idea on what could be the issue? Is there any workaround for this?
thanks, Atticus

Tom Molesworth

unread,
Jul 27, 2016, 8:49:20 AM7/27/16
to rabbitm...@googlegroups.com

Hi,

On 27/07/16 13:17, Attila Rozsa wrote:

07-27 08:12:26.157: D/remotemonitormq(833): MQuri0
07-27 08:12:27.277: D/dalvikvm(833): GC_FOR_ALLOC freed 379K, 17% free 2637K/3140K, paused 49ms, total 54ms
07-27 08:12:27.577: D/dalvikvm(833): GC_FOR_ALLOC freed 19K, 16% free 2661K/3140K, paused 230ms, total 231ms
07-27 08:12:27.587: I/dalvikvm-heap(833): Forcing collection of SoftReferences for 1345270078-byte allocation
07-27 08:12:27.667: D/dalvikvm(833): GC_BEFORE_OOM freed 70K, 18% free 2590K/3140K, paused 75ms, total 75ms
07-27 08:12:27.667: E/dalvikvm-heap(833): Out of memory on a 1345270078-byte allocation.

So 1345270078 is 0x502f313e, which also happens to be the characters in the trailing part of HTTP/1.1 (technically "P/1>", that last character is mangled because the allocation is 16 bytes larger). I think that'd make more sense than a genuine 1.3GB allocation requirement, anyway!

Best guess is that you're connecting to the wrong port:

"AMQP Connection 146.148.23.73:443"

:443 is typically https, not AMQP. Information about ports can be found in https://www.rabbitmq.com/networking.html but I'd expect :5672 or :5671. Presumably the CloudAMQP docs should also have a section about this.

cheers,

Tom

Attila Rozsa

unread,
Jul 28, 2016, 5:46:16 AM7/28/16
to rabbitmq-users
Thanks Tom, that was it.

regards, Atticus

Yannic Klem

unread,
Aug 16, 2021, 5:35:00 AM8/16/21
to rabbitmq-users
Hi together,
Sorry for warming up this old topic, but I recently ran into this issue and I'd like to know if this is really the desired behavior of the RabbitMQ Java Client for accidentally used wrong ports.
I also got an OutOfMemoryError when using com.rabbitmq:amqp-client:5.13.0.

I'm wondering if there is any chance to handle this differently since an OutOfMemoryError could lead to the crash of an application if it for example makes use of the 'ExitOnOutOfMemoryError' JVM flag.
Of course you could say that one just needs to configure the URI correctly, but what about applications that have their connections configured by users?

If anybody would like to reproduce the issue just configure for example "amqps://google.de:443".

Thank you for your time,
Yannic
Reply all
Reply to author
Forward
0 new messages