rust-mq
rust-mq copied to clipboard
Reconnection not happening (exactly) in ReconnectAfter duration
Reconnect is working but not as specified by ReconnnectAfter
duration
opts.set_keep_alive(15);
opts.set_reconnect(ReconnectMethod::ReconnectAfter(Duration::new(5,0)));
let mut client = opts.connect(address.as_str(), netopt).unwrap();
client.subscribe(topic.as_str()).unwrap();
client.await().unwrap();
loop {
match client.await() {
Ok(result) => match result {
Some(message) => println!("{:?}", message),
None => println!("."),
},
Err(_) => continue,
}
}
My test: Take the broker down and bring it up immediately again.
Here is the client log
ERROR:mqttc::client: UnexpectedEof
INFO:mqttc::client: Reconnect in 5 seconds
WARN:mqttc::client: mqttc is already connected
.
DEBUG:mqttc::client: Pingreq
TRACE:mqttc::client: Pingreq
ERROR:mqttc::client: UnexpectedEof
INFO:mqttc::client: Reconnect in 5 seconds
WARN:mqttc::client: mqttc is already connected
INFO:mqttc::client: Disconnected mqttc_2017656392
INFO:mqttc::client: Reconnect in 5 seconds
DEBUG:mqttc::client: Connect mqttc_2017656392
TRACE:mqttc::client: Connect(Connect { protocol: MQTT(4), keep_alive: 15, client_id: "mqttc_2017656392", clean_session: true, last_will: None, username: None, password: None })
TRACE:mqttc::client: Connack(Connack { session_present: false, code: Accepted })
INFO:mqttc::client: Connection accepted
Reconnection is being tried but it's failing because of ClientState::Connected. Actual client disconnection is happening after there is no PingResp
and the next reconnect try is being successful.
Is this the expected behaviour? Shouldn't client be in DisconnectedState
before retrying connection?