Skip to content

Commit db1f261

Browse files
authored
fix(rumqttc): acks with failure reason code should not be state error (#877)
1 parent 15c3968 commit db1f261

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

rumqttc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3636
* Ordering of `State.events` related to `QoS > 0` publishes
3737
* Filter PUBACK in pending save requests to fix unexpected PUBACK sent to reconnected broker.
3838
* Resume session only if broker sends `CONNACK` with `session_present == 1`.
39+
* Remove v5 PubAck/PubRec/PubRel/PubComp/Sub/Unsub failures from `StateError` and log warnings on these failures.
3940

4041
### Security
4142

rumqttc/src/v5/state.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ pub enum StateError {
5151
reason_code: DisconnectReasonCode,
5252
reason_string: Option<String>,
5353
},
54-
#[error("Unsubscribe failed with reason '{reason:?}' ")]
55-
UnsubFail { reason: UnsubAckReason },
56-
#[error("Subscribe failed with reason '{reason:?}' ")]
57-
SubFail { reason: SubscribeReasonCode },
58-
#[error("Publish acknowledgement failed with reason '{reason:?}' ")]
59-
PubAckFail { reason: PubAckReason },
60-
#[error("Publish receive failed with reason '{reason:?}' ")]
61-
PubRecFail { reason: PubRecReason },
62-
#[error("Publish release failed with reason '{reason:?}' ")]
63-
PubRelFail { reason: PubRelReason },
64-
#[error("Publish completion failed with reason '{reason:?}' ")]
65-
PubCompFail { reason: PubCompReason },
6654
#[error("Connection failed with reason '{reason:?}' ")]
6755
ConnFail { reason: ConnectReturnCode },
6856
#[error("Connection closed by peer abruptly")]
@@ -252,7 +240,9 @@ impl MqttState {
252240
SubscribeReasonCode::Success(qos) => {
253241
debug!("SubAck Pkid = {:?}, QoS = {:?}", suback.pkid, qos);
254242
}
255-
_ => return Err(StateError::SubFail { reason: *reason }),
243+
_ => {
244+
warn!("SubAck Pkid = {:?}, Reason = {:?}", suback.pkid, reason);
245+
},
256246
}
257247
}
258248
Ok(None)
@@ -264,7 +254,7 @@ impl MqttState {
264254
) -> Result<Option<Packet>, StateError> {
265255
for reason in unsuback.reasons.iter() {
266256
if reason != &UnsubAckReason::Success {
267-
return Err(StateError::UnsubFail { reason: *reason });
257+
warn!("UnsubAck Pkid = {:?}, Reason = {:?}", unsuback.pkid, reason);
268258
}
269259
}
270260
Ok(None)
@@ -374,9 +364,8 @@ impl MqttState {
374364
if puback.reason != PubAckReason::Success
375365
&& puback.reason != PubAckReason::NoMatchingSubscribers
376366
{
377-
return Err(StateError::PubAckFail {
378-
reason: puback.reason,
379-
});
367+
warn!("PubAck Pkid = {:?}, reason: {:?}", puback.pkid, puback.reason);
368+
return Ok(None);
380369
}
381370

382371
if let Some(publish) = self.check_collision(puback.pkid) {
@@ -408,9 +397,8 @@ impl MqttState {
408397
if pubrec.reason != PubRecReason::Success
409398
&& pubrec.reason != PubRecReason::NoMatchingSubscribers
410399
{
411-
return Err(StateError::PubRecFail {
412-
reason: pubrec.reason,
413-
});
400+
warn!("PubRec Pkid = {:?}, reason: {:?}", pubrec.pkid, pubrec.reason);
401+
return Ok(None);
414402
}
415403

416404
// NOTE: Inflight - 1 for qos2 in comp
@@ -429,9 +417,8 @@ impl MqttState {
429417
self.incoming_pub.set(pubrel.pkid as usize, false);
430418

431419
if pubrel.reason != PubRelReason::Success {
432-
return Err(StateError::PubRelFail {
433-
reason: pubrel.reason,
434-
});
420+
warn!("PubRel Pkid = {:?}, reason: {:?}", pubrel.pkid, pubrel.reason);
421+
return Ok(None);
435422
}
436423

437424
let event = Event::Outgoing(Outgoing::PubComp(pubrel.pkid));
@@ -457,9 +444,8 @@ impl MqttState {
457444
self.outgoing_rel.set(pubcomp.pkid as usize, false);
458445

459446
if pubcomp.reason != PubCompReason::Success {
460-
return Err(StateError::PubCompFail {
461-
reason: pubcomp.reason,
462-
});
447+
warn!("PubComp Pkid = {:?}, reason: {:?}", pubcomp.pkid, pubcomp.reason);
448+
return Ok(None);
463449
}
464450

465451
self.inflight -= 1;

0 commit comments

Comments
 (0)