Skip to content

Commit

Permalink
Bugfix: crash on MQTT async client restart
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Nov 12, 2024
1 parent a9595ee commit cca1a60
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mqtt/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ enum AsyncCommand {
Unsubscribe,
Publish { qos: QoS, retain: bool },
SetUri,
None,
}

#[derive(Debug)]
Expand Down Expand Up @@ -886,7 +887,7 @@ impl EspAsyncMqttClient {
) {
// Placeholder work item. This will be replaced by the first actual work item.
let mut work = AsyncWork {
command: AsyncCommand::Unsubscribe,
command: AsyncCommand::None,
topic: caps
.map(|cap| alloc::vec::Vec::with_capacity(cap.1))
.unwrap_or_default(),
Expand All @@ -903,6 +904,7 @@ impl EspAsyncMqttClient {
// this thread to process it by calling into the C library and write the result.
while channel.share(&mut work) {
match work.command {
AsyncCommand::None => {}
AsyncCommand::Subscribe { qos } => {
let topic =
unsafe { core::ffi::CStr::from_bytes_with_nul_unchecked(&work.topic) };
Expand Down Expand Up @@ -998,7 +1000,7 @@ impl<'a> EspMqttEvent<'a> {
Self(event)
}

#[allow(non_upper_case_globals)]
#[allow(non_upper_case_globals, non_snake_case)]
pub fn payload(&self) -> EventPayload<'_, EspError> {
match self.0.event_id {
esp_mqtt_event_id_t_MQTT_EVENT_ERROR => EventPayload::Error(&ERROR), // TODO
Expand Down

0 comments on commit cca1a60

Please sign in to comment.