Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/runtime/nodes/mqtt_shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,26 @@ async fn drive(
loop {
match poller.poll().await {
Ok(PollEvent::Connected) => {
// Re-subscribe and publish birth, but NOT inline: each client
// request enqueues into a bounded channel that only this driver
// drains by polling. Awaiting many requests here (e.g. dozens of
// mqtt-in filters) fills the queue while the loop is not polling,
// which deadlocks the connection. Hand the work to a detached
// task so the event loop keeps being polled and the queue drains.
let filters: Vec<(String, u8)> = subs
.lock()
.unwrap()
.iter()
.map(|s| (s.filter.clone(), s.qos))
.collect();
for (filter, qos) in filters {
let _ = client.subscribe(&filter, qos).await;
}
birth.publish(client.as_ref()).await;
let client = client.clone();
let birth = birth.clone();
tokio::spawn(async move {
for (filter, qos) in filters {
let _ = client.subscribe(&filter, qos).await;
}
birth.publish(client.as_ref()).await;
});
}
Ok(PollEvent::Message(m)) => {
let subs = subs.lock().unwrap();
Expand Down