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

Repeating exception: "Client is connected (32100)" #209

Open
3 tasks done
algrid opened this issue May 12, 2017 · 4 comments
Open
3 tasks done

Repeating exception: "Client is connected (32100)" #209

algrid opened this issue May 12, 2017 · 4 comments

Comments

@algrid
Copy link

algrid commented May 12, 2017

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

  • Bug exists Release Version 1.1.1 (Java Repository Master Branch)
  • Bug exists in Snapshot Version 1.1.2-SNAPSHOT (Android Service Repository Master Branch)
  • Bug is just in the Sample Application.

Android API Version Bug Seen on: API 19

Android Version Bug Seen on: 4.4.2

Description of Bug:

My app starts and connects to a MQTT broker. Everything is done almost the same way as in the example app. On first run after install everything is ok, but after app restart I start getting error messages every 5 min: "Failed to connect to: tcp://my-broker:1883 Client is connected (32100)".

I had the same problem with the example app from master (but currently I get build errors when I download master and try to build the example app).

Console Log output (if available):

05-12 13:53:42.014 31509-31509/android.ch.mitto.missito E/MqttConnection: Exception occurred attempting to reconnect: Client is connected
05-12 13:53:42.014 31509-31509/android.ch.mitto.missito E/MQTTConnectionManager: Failed to connect to: tcp://192.168.2.24:1883
                                                                                 Client is connected (32100)
                                                                                     at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
                                                                                     at org.eclipse.paho.client.mqttv3.MqttAsyncClient.reconnect(MqttAsyncClient.java:1144)
                                                                                     at org.eclipse.paho.android.service.MqttConnection.reconnect(MqttConnection.java:1049)
                                                                                     at org.eclipse.paho.android.service.MqttService.reconnect(MqttService.java:342)
                                                                                     at org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver.onReceive(MqttService.java:827)
                                                                                     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:848)
                                                                                     at android.os.Handler.handleCallback(Handler.java:733)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                     at android.os.Looper.loop(Looper.java:157)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5872)
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
                                                                                     at dalvik.system.NativeStart.main(Native Method)
@jflavio11
Copy link

jflavio11 commented Jul 25, 2017

Hi @algrid!

I also had this issue when connection state changes very fast, Paho does not detects this so network is too slow or simply disconnects, MqttService thinks is still connected to the broker (Comms object does not change the connection state).

So a workaround I found was handling the exception that is catched on reconnect() method from MqttConnection class.

More or less, it is something like this:

... } catch (MqttException ex){ service.traceDebug(TAG,"Exception occurred attempting to reconnect: " + ex.getMessage()); Log.e(TAG, "Exception occurred attempting to reconnect: " + ex.getMessage()); setConnectingState(false); handleException(resultBundle, ex); if(ex.getReasonCode() == MqttException.REASON_CODE_CLIENT_CONNECTED || ex.getReasonCode() == MqttException.REASON_CODE_CONNECT_IN_PROGRESS) { service.traceDebug(TAG,"Speeding ping first..."); alarmPingSender.schedule(100); service.traceDebug(TAG,"Changing keepAliveInterval to 300s"); alarmPingSender.changeKeepAlive(300); } else { // if not we only accelerate the ping service.traceDebug(TAG,"Sending PING..."); alarmPingSender.schedule(100); } }

For this, I created changeKeepAlive() method on AlarmPingSender:
comms.getClientState().setKeepAliveInterval(seconds * 1000);

With this, I assure I really had the connection established because I force sending a PINGREQ.

Regards,
Flavio

@sathishkumars92
Copy link

@jflavio1 I'm also getting the same issue. I can't understand that how sending ping to server will connect to server if its disconnected.

@phanuelayuka
Copy link

I am also getting the same problem. Did you guys resolve this ?

@JJDS
Copy link

JJDS commented Aug 30, 2021

I am also getting the same problem. Did you guys resolve this ?

I have the same problem. I can't found a solution. Have someone already solve the issue?
Thanks.

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

5 participants