eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 884 forks source link

MqttAsyncClient connect () infinite loop #856

Open aspring66 opened 3 years ago

aspring66 commented 3 years ago

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

If this is a bug regarding the Android Service, please raise the bug here instead: https://github.com/eclipse/paho.mqtt.android/issues/new

Hello,

I observed the conditon described below that, from my poit of view, seams to be a bug. I started a "dummy" broker using netcat.

nc -l -m 100 -k 10.60.2.43 1883

Then I started a MQTT client based on Paho MqttCLient lib (version 1.2.5) that tries to connect to the dummy broker

In this scenario, the client is abviuosly able to open a socket and send the MQTT CONNET message but the "dummy" broker does not answer to the request.

The behaviour expected should be a socket close after a definied timeout. Instead the client remain in a infinete loop in the receiver thread:

13:53:34,879 FINE [org.eclipse.paho.client.mqttv3.internal.CommsReceiver] (MQTT Rec: MYCLIENT) MYCLIENT: network read message 13:53:35,880 FINE [org.eclipse.paho.client.mqttv3.internal.CommsReceiver] (MQTT Rec: MYCLIENT) MYCLIENT: network read message 13:53:36,881 FINE [org.eclipse.paho.client.mqttv3.internal.CommsReceiver] (MQTT Rec: MYCLIENT) MYCLIENT: network read message 13:53:37,882 FINE [org.eclipse.paho.client.mqttv3.internal.CommsReceiver] (MQTT Rec: MYCLIENT) MYCLIENT: network read message 13:53:38,883 FINE [org.eclipse.paho.client.mqttv3.internal.CommsReceiver] (MQTT Rec: MYCLIENT) MYCLIENT: network read message

My impression is that the problem is linked to the next code lines in org.eclipse.paho.client.mqttv3.internal.CommsReceiver: //LINE 169

`

else {

// fix for bug 719

if (!clientComms.isConnected() && !clientComms.isConnecting()) {

                     throw new IOException("Connection is lost.");

}

}

` I tried to recover from this condition calling disconect(), disconnectForcibly, close(true), but none of this methods works becasue of the current state of the client is "connecting". The only way to recover from this situation is to stop and restart the program, not applicable in a production environemnt.

Any suggetion to resolve the problem? Thank you.

pisua commented 3 years ago

Hi, i encounter the same in issue in my test with the verson 1.2.5 of the client. That was not the case with 1.2.0 before. Do you know if the problème exists in the SNAPSHOT version 1.2.6 and if it's ok to use it?

Thanks in advance