aws-sdk-android icon indicating copy to clipboard operation
aws-sdk-android copied to clipboard

Fatal Exception: java.lang.OutOfMemoryError

Open ranjeet-porter opened this issue 1 year ago • 7 comments

Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:733) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.scheduleReconnect(AWSIotMqttManager.java:1377) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.handleConnectionFailure(AWSIotMqttManager.java:1356) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectWithIAM(AWSIotMqttManager.java:1346) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectToSession(AWSIotMqttManager.java:1278) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager$4.run(AWSIotMqttManager.java:1385) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.os.HandlerThread.run(HandlerThread.java:65)

SDK Version : com.amazonaws:aws-android-sdk-iot: 2.16.12 Platform : Android

ranjeet-porter avatar Jul 22 '24 06:07 ranjeet-porter

Hi @ranjeet-porter, can you provide us with some more details around how to reproduce this with some code snippets, call pattern, and set up? Out of memory exception could be caused by different processes, were you able to profile your app during the crash to identify what's using up the memory?

lawmicha avatar Jul 22 '24 18:07 lawmicha

Hi @lawmicha Sure. I have setup my mqtt re-connection with -1 mean infinite times so it is calling reconnection multiple times within second then causing out of memory after certain times.

Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again at java.lang.Thread.nativeCreate(Thread.java) at java.lang.Thread.start(Thread.java:733) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.scheduleReconnect(AWSIotMqttManager.java:1377) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.handleConnectionFailure(AWSIotMqttManager.java:1356) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectWithIAM(AWSIotMqttManager.java:1346) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager.reconnectToSession(AWSIotMqttManager.java:1278) at com.amazonaws.mobileconnectors.iot.AWSIotMqttManager$4.run(AWSIotMqttManager.java:1385) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.os.HandlerThread.run(HandlerThread.java:65)

Device Specification:

Device Brand:Xiaomi Model:Redmi 8A Dual Orientation:Portrait RAM free: 933.63 MB Disk free: 5.14 GB Operating System Version:Android 9 Orientation:Portrait Rooted: No Crash Date:Jul 20, 2024, 8:31:33 PM App version:5.101.4 (371) User ID:9767175862620

ranjeet-porter avatar Jul 23 '24 05:07 ranjeet-porter

could you share the code snippets for this?

I have setup my mqtt re-connection with -1

lawmicha avatar Jul 26 '24 17:07 lawmicha

AWSIotMqttManager(mqttConfig.clientId, mqttConfig.awsIotEndPoint).apply {
    mqttConfig.mqttClientConfig?.let {
        keepAlive = it.keepAlive
        isAutoReconnect = it.isAutoReconnect
        isOfflinePublishQueueEnabled = it.isOfflinePublishQueueEnabled
        maxAutoReconnectAttempts = -1
        setReconnectRetryLimits(
            it.minReconnectRetryTime,
            it.maxReconnectRetryTime,
        )
    }
}

ranjeet-porter avatar Jul 29 '24 15:07 ranjeet-porter

@ranjeet-porter

I'm a bit confused by

Sure. I have setup my mqtt re-connection with -1 mean infinite times so it is calling reconnection multiple times within second then causing out of memory after certain times.

What values have you set for setReconnectRetryLimits minTimeout and maxTimeout (Default is 4 seconds and 64 seconds). Those values are set in seconds so I wouldn't expect a retry to be attempted at more than once per second. The retries should then exponentially backoff to the maxTimeout value set there.

Are you setting both of those values to 0?

tylerjroach avatar Jul 29 '24 17:07 tylerjroach

I set minTimeout = 4 and maxTimeout = 15 but with maxAttempt is -1 and I got out of memory exception

ranjeet-porter avatar Jul 30 '24 08:07 ranjeet-porter

@ranjeet-porter It would be helpful if you were able to add logs of a connect attempt session. I believe you can enable in the SDK by simply calling LogFactory.setLevel(LogFactory.Level.DEBUG);.

Also curious if you have tried a high (but not infinite value). Ex: maxAttempt = 100. I'm curious if you still see the same behavior.

In a quick glance at the code, the exponential backoff should prevent too many attempts, but to receive OOM exceptions seems to indicate that reconnects are rapidly being attempted.

tylerjroach avatar Aug 15 '24 12:08 tylerjroach

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jan 14 '25 14:01 github-actions[bot]