Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.OutOfMemoryError #3616

Open
ranjeet-porter opened this issue Jul 22, 2024 · 7 comments
Open

Fatal Exception: java.lang.OutOfMemoryError #3616

ranjeet-porter opened this issue Jul 22, 2024 · 7 comments
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor

Comments

@ranjeet-porter
Copy link

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

@lawmicha
Copy link
Member

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 lawmicha added iot Issues with the AWS Android SDK for Internet of Things (IoT) bug Something isn't working pending-community-response Issue is pending response from the issue requestor labels Jul 22, 2024
@ranjeet-porter
Copy link
Author

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

@lawmicha
Copy link
Member

could you share the code snippets for this?

I have setup my mqtt re-connection with -1

@ranjeet-porter
Copy link
Author

ranjeet-porter commented Jul 29, 2024

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,
        )
    }
}

@tylerjroach
Copy link
Member

@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?

@ranjeet-porter
Copy link
Author

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

@tylerjroach tylerjroach added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Aug 13, 2024
@tylerjroach
Copy link
Member

@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 tylerjroach added pending-community-response Issue is pending response from the issue requestor and removed pending-maintainer-response Issue is pending response from an Amplify team member labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor
Projects
None yet
Development

No branches or pull requests

3 participants