eclipse-paho / eclipse-paho/paho.mqtt.java

Possible race condition in onSucess in IMqttActionListener for connection status

Open
#722 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

I would like to send a message when the client connects to the broker. I added an IMqttActionListener to the connect parameters. About half the time. it works, the other half there is an exception thrown in the onSuccess function when it tries to send the message. Here is the output when it fails:

> MQTT connected to tcp://broker.hivemq.com:1883
> 4
> reason 32104
> msg Client is not connected

```
public void onSuccess(IMqttToken arg0) {
System.out.println("MQTT connected to " + arg0.getClient().getServerURI());
byte[] payload = (this.connectPayload + MqttConnectionListener.getIso8601String()).getBytes();
try {
arg0.getClient().publish(this.connectTopic, payload, this.qos, this.connectRetained);
} catch (MqttPersistenceException e) {
System.out.println("3");
Demo.printMqttException(e);
} catch (MqttException e) {
System.out.println("4");
Demo.printMqttException(e);
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.