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

Mqtt client does NOT auto reconnect when receiving exception "Timed out as no write activity"

Open
#1,065 0 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

Version: spring integration mqtt 6.2.1
Java: 11/17/21
Configuration:
autoReconnect: true
cleanSession: true

Expected behaviour:

after receiving exception "Timed out as no write activity, keepAlive=60.000.000.000 lastOutboundActivity=6.114.183.067.622.000 lastInboundActivity=6.114.206.492.058.900 time=6.114.423.973.125.000 lastPing=6.114.183.067.640.300"
the client should reconnect to the broker

Actual behaviour:
the client never reconnects

How to reproduce:

1) Write simple mqtt client
2) Start in debug mode
3) Set a break point when receiving message
4) Publish a message via mqtt explorer or whatever client you want
5) Stop in break point for, at least, 4 minutes
6) Proceed in the application

We identified the potential issue in the callback class.

`public class CommsCallback implements Runnable`

The problem looks like is in this method.

`public void start(String threadName, ExecutorService executorService) {
this.threadName = threadName;
synchronized(this.lifecycle) {
if (this.current_state == CommsCallback.State.STOPPED) {
this.messageQueue.clear();
this.completeQueue.clear();
this.target_state = CommsCallback.State.RUNNING;
if (executorService == null) {
(new Thread(this)).start();
} else {
this.callbackFuture = executorService.submit(this);
}
}
}

while(!this.isRunning()) {
try {
Thread.sleep(100L);
} catch (Exception var4) {
}
}

}`

When receiving exception the variable `current_state` remains in ` CommsCallback.State.RUNNING`.

While the variable `target_state` is in status `CommsCallback.State.STOPPED`

But, if I stop and restart the mqtt broker, the behaviour is correct (the client reconnects).

I try to open the issue even if I know that the last update on this project was long time ago.

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.