From e92d8c9cef09c674f839496c70d3d79b3d2000ed Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 7 Jan 2023 22:22:49 -0600 Subject: [PATCH] mqtt: Break out of receive loop on disconnect Apparently, the `AsyncReceiver` stream produces nested `Option` objects. The outer is `None` if "the stream is exhausted," which is somehow different than the connection being closed; the inner `Option` is `None` in that case. We were originally ignoring the inner `None`, but just causes the async task to go into a busy loop when connection is closed. We need to break out of the loop there instead. --- src/mqtt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mqtt.rs b/src/mqtt.rs index 6c8e6c7..179f47f 100644 --- a/src/mqtt.rs +++ b/src/mqtt.rs @@ -103,7 +103,7 @@ impl<'a> MqttClient<'a> { client.disconnect(None); }); while let Some(msg) = self.stream.next().await { - let Some(msg) = msg else {continue}; + let Some(msg) = msg else {break}; trace!("Received message: {:?}", msg); for m in self.topics.matches(msg.topic()) { match m.1 {