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

Invalid ClientHandle, IllegalArgumentException #238

Open
jinseongho opened this issue Sep 1, 2017 · 11 comments
Open

Invalid ClientHandle, IllegalArgumentException #238

jinseongho opened this issue Sep 1, 2017 · 11 comments

Comments

@jinseongho
Copy link

Please fill out the form below before submitting, thank you!

  • [v] Bug exists Release Version 1.1.1 (Java Repository Master Branch)

Description of Bug:

In some cases, an error occurs immediately when MQTT is connected.

Console Log output (if available):

Fatal Exception: java.lang.IllegalArgumentException Invalid ClientHandle Raw Text

  | org.eclipse.paho.android.service.MqttService.getConnection (SourceFile:588)
  | org.eclipse.paho.android.service.MqttService.connect (SourceFile:328)
  | org.eclipse.paho.android.service.MqttAndroidClient.doConnect (SourceFile:467)
  | org.eclipse.paho.android.service.MqttAndroidClient.access$002 (SourceFile:76)
  | org.eclipse.paho.android.service.MqttAndroidClient$1.run (SourceFile:435)

@shubhral
Copy link

shubhral commented Dec 8, 2017

Any updates on this? I've been noticing some crashes in crashlytics now due to this issue.

@algrid
Copy link

algrid commented Jan 2, 2018

I'm having the same issue calling MqttAndroidClient.isConnected:

java.lang.IllegalArgumentException: Invalid ClientHandle
    at org.eclipse.paho.android.service.MqttService.getConnection(MqttService.java:588)
    at org.eclipse.paho.android.service.MqttService.isConnected(MqttService.java:413)
    at org.eclipse.paho.android.service.MqttAndroidClient.isConnected(MqttAndroidClient.java:251)
...

@kylebake
Copy link

Having the same issue. From the crash report:

Exception java.lang.IllegalArgumentException: Invalid ClientHandle
org.eclipse.paho.android.service.MqttService.getConnection (MqttService.java:588)
org.eclipse.paho.android.service.MqttService.isConnected (MqttService.java:413)
org.eclipse.paho.android.service.MqttAndroidClient.isConnected (MqttAndroidClient.java:251)
com.mrselectronic.cpk.Services.MQTTService$5.run (MQTTService.java:291)

Is this a bug with the library itself or is there a workaround? I'm fairly certain I'm handling the client object correctly as everything behaves as expected, except for these exceptions, which I have a hard time recreating.

@igumiku
Copy link

igumiku commented Jun 4, 2018

any update on this?

@kulebin
Copy link

kulebin commented Jun 4, 2018

I think this issue is not valid, as I understand such issue may occur when you try perform connect, disconnect or isConnected actions during connecting or disconnecting process. For this purpose the library provides such useful tool as IMqttToken. It allows to handle a called operation status and do not call another one before ongoing action is finished.

@igumiku
Copy link

igumiku commented Jun 5, 2018

@kulebin you are right! Thanks.

@plentz
Copy link

plentz commented Jun 15, 2018

Probably related to #183 #99 #84 #8

@lakst
Copy link

lakst commented Jul 30, 2018

It happens rarely like for only 1% of my users, but I'm unsure as to why and when this happens? Any pointers?

@naimaryan1
Copy link

What is the ETA on this issue getting addressed, im getting this crash when i call disconnect() or unsubscribe().

This is my log:

2018-11-30 10:30:54.866 3468-3468/com.xyz.controller.core E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xyz.controller.core, PID: 3468
java.lang.IllegalArgumentException: Invalid ClientHandle
at org.eclipse.paho.android.service.MqttService.getConnection(MqttService.java:588)
at org.eclipse.paho.android.service.MqttService.unsubscribe(MqttService.java:545)
at org.eclipse.paho.android.service.MqttAndroidClient.unsubscribe(MqttAndroidClient.java:1214)
at org.eclipse.paho.android.service.MqttAndroidClient.unsubscribe(MqttAndroidClient.java:1168)
at com.xyz.controller.core.fragments.ExternalSensorArrayAdapter.onClick(ExternalSensorArrayAdapter.java:373)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22433)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6145)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2018-11-30 10:30:55.004 1724-2031/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ LISTEN id=66, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN&FOREGROUND] ]

@HorkyChen
Copy link

HorkyChen commented Dec 17, 2018

This issue could be reproduced if the disconnect() was called, the clientHandle in connections was removed in MqttService::disconnect() without calling MqttAndroidClient::disconnected(), so the clientHandle had a invalid value from then on.

So, what I do to fix this issue is to reset clientHandle in MqttService::disconnect().

@kapeas
Copy link

kapeas commented Jan 20, 2020

Hi, I have been facing this issue "randomly" until I understood the problem better.
In my scenario, I have an app that is constantly subscribed to a topic and when receives a message it sends a new one confirming the job has been received.

I was creating new producers everytime app sends a message, and had a static (companion) refference to the MQclient. The invalid client handle appeared because my onSuccess message tried to publish a new message with a client that was different from the IMqttToken issuer client.

In more concise words, if you are executing parallel clients, be sure every client is called from the propper IMqttToken. Client must be the same that issued the token.

Hopes this helps others facing the problem.
And thanks for the library, it's really useful on my everyday.

guness added a commit to guness/paho.mqtt.android that referenced this issue Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests