Skip to content

Commit b4c0854

Browse files
authored
Merge pull request #3462 from reubenmiller/fix-mqtt-topic-sub-without-session
fix: subscribe to topics on reconnection when session persistence is not enabled or broken
2 parents eea0a40 + 0aff528 commit b4c0854

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

crates/common/mqtt_channel/src/connection.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,10 @@ impl Connection {
271271
.await?;
272272
}
273273

274-
if config.session_name.is_none() {
274+
if config.session_name.is_none() || !ack.session_present {
275275
// Workaround for https://github.com/bytebeamio/rumqtt/issues/250
276-
// If session_name is not provided, then re-subscribe
276+
// If session_name is not provided or if the broker session persistence
277+
// is not enabled or working, then re-subscribe
277278

278279
let subscriptions = config.subscriptions.filters();
279280
// Need check here otherwise it will hang waiting for a SubAck, and none will come when there is no subscription.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*** Settings ***
2+
Resource ../../resources/common.resource
3+
Library Cumulocity
4+
Library ThinEdgeIO
5+
6+
Test Setup Custom Setup
7+
Test Teardown Get Logs
8+
9+
Test Tags theme:mqtt theme:c8y
10+
11+
12+
*** Test Cases ***
13+
Agent Processes Operations After Local MQTT Broker Disconnects Without Mosquitto Persistence Settings
14+
# Force tedge-agent to disconnect by restarting mosquitto
15+
Restart Service mosquitto
16+
${operation}= Cumulocity.Get Configuration tedge-configuration-plugin
17+
Operation Should Be SUCCESSFUL ${operation}
18+
19+
20+
*** Keywords ***
21+
Custom Setup
22+
${DEVICE_SN}= Setup
23+
Set Suite Variable $DEVICE_SN
24+
Device Should Exist ${DEVICE_SN}
25+
# Remove mosquitto persistence settings
26+
Execute Command sed -i '/^persistence.*/d' /etc/mosquitto/mosquitto.conf
27+
28+
# Restart mosquitto to start again ignoring pre-existing persisted data
29+
# Note: Tests should not rely on the mosquitto service restarting in the test setup
30+
Restart Service mosquitto

0 commit comments

Comments
 (0)