diff --git a/src/runtime/nodes/mqtt.rs b/src/runtime/nodes/mqtt.rs index 9607c51..96a88d7 100644 --- a/src/runtime/nodes/mqtt.rs +++ b/src/runtime/nodes/mqtt.rs @@ -471,11 +471,17 @@ impl Node for MqttOutNode { status("error", "no_topic", Value::Null); continue; }; - if let Err(e) = shared - .publish(&topic, self.qos, self.retain, value_to_bytes(&msg.payload)) - .await - { - status("error", "publish_error", json!({ "error": e })); + // A publish blocks when the broker is down (the client's + // request queue fills). Race it against shutdown so Stop + // still works — otherwise the node is aborted before it + // can release the shared connection (driver leak). + tokio::select! { + _ = NodeCtx::shutdown_requested(&mut shutdown) => break, + r = shared.publish(&topic, self.qos, self.retain, value_to_bytes(&msg.payload)) => { + if let Err(e) = r { + status("error", "publish_error", json!({ "error": e })); + } + } } } None => break,