eclipse / paho.mqtt.android

MQTT Android
Other
2.92k stars 881 forks source link

Android Paho client leaked intentReceiver issue #355

Open rakeshkumar0023 opened 5 years ago

rakeshkumar0023 commented 5 years ago

Please fill out the form below before submitting, thank you! Android API Version Bug Seen on:24

Android Version Bug Seen on: 7.0

I am using android service version 1.1.1 and mqtt client version 1.2.1.

Description of Bug:

I have created a sample mqtt android application in which i have implemented all methods of mqtt client like connect, disconnect, subscribe, unsubscribe.I have implemented manual auto reconnect which means that when a disconnection happens i am calling connect method after 500 ms.

I am getting leaked intentReceiver, only in MI devices after 3-4 min of connection. In Other devices it is happening, when mobile network is not stable due to which frequent connection and disconnection happens.

In my close implementation, i have followed these steps to close a connection: client.disconnect() //here client is MqttAndroidClient client.unregisterResources() client.setcallback(null) client.close() client =null

Console Log output (if available):

2019-03-19 15:04:21.774 10143-10488/com.eclipse.mqtt D/AlarmPingSender: Success. Release lock(MqttService.client.device_test):1552988061774 2019-03-19 15:04:51.757 10143-10143/com.eclipse.mqtt D/AlarmPingSender: Sending Ping at:1552988091757 2019-03-19 15:04:51.763 10143-10143/com.eclipse.mqtt D/AlarmPingSender: Schedule next alarm at 1552988121763 2019-03-19 15:04:51.763 10143-10143/com.eclipse.mqtt D/AlarmPingSender: Alarm scheule using setExactAndAllowWhileIdle, next: 30000 2019-03-19 15:04:51.894 10143-10488/com.eclipse.mqtt D/AlarmPingSender: Success. Release lock(MqttService.client.device_test):1552988091894 2019-03-19 15:04:56.438 10143-10143/com.eclipse.mqtt E/ActivityThread: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@7107401 that was originally registered here. Are you missing a call to unregisterReceiver()? android.app.IntentReceiverLeaked: Service org.eclipse.paho.android.service.MqttService has leaked IntentReceiver org.eclipse.paho.android.service.AlarmPingSender$AlarmReceiver@7107401 that was originally registered here. Are you missing a call to unregisterReceiver()? at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1172) at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:955) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1340) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1320) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1314) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:596) at org.eclipse.paho.android.service.AlarmPingSender.start(AlarmPingSender.java:74) at org.eclipse.paho.client.mqttv3.internal.ClientState.connected(ClientState.java:1201) at org.eclipse.paho.client.mqttv3.internal.ClientState.notifyReceivedAck(ClientState.java:1037) at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:150) at java.lang.Thread.run(Thread.java:760) 2019-03-19 15:04:56.445 10143-13467/com.eclipse.mqtt D/AlarmPingSender: Unregister alarmreceiver to MqttServicedevice_test 2019-03-19 15:04:56.461 10143-10143/com.eclipse.mqtt I/MqttTest: Connection Lost 2019-03-19 15:04:56.467 10143-13468/com.eclipse.mqtt I/MqttTest: Reconnecting waiting for 500 ms 2019-03-19 15:04:56.568 10143-13468/com.eclipse.mqtt I/MqttTest: getMqttConnectOPtion keepalive 30 2019-03-19 15:04:57.120 10143-13470/com.eclipse.mqtt D/AlarmPingSender: Register alarmreceiver to MqttServiceMqttService.pingSender.device_test 2019-03-19 15:04:57.126 10143-13470/com.eclipse.mqtt D/AlarmPingSender: Schedule next alarm at 1552988127126 2019-03-19 15:04:57.126 10143-13470/com.eclipse.mqtt D/AlarmPingSender: Alarm scheule using setExactAndAllowWhileIdle, next: 30000

ranabdc commented 4 years ago

i am facing the same error. did you get a fix yet?

aristotelis-vryonidis commented 4 years ago

Hi there I m facing the same issue on Android 10 , the below sequence reproduces it try { // unsubscribe here unsubscribe("testTopic"); mqttClient.unregisterResources(); mqttClient.close(); mqttClient.disconnect(); mqttClient.setCallback(null); mqttClient = null; } catch (MqttException e) { Timber.e( e.toString()); }

In the issue below it says it should work but still doesn't https://github.com/eclipse/paho.mqtt.android/issues/178

bhaveshjethani774 commented 1 year ago

@knolleary @ralight @ranabdc do we have any workaround on this point?