fix(service/sending): Use Flush to wake queued destinations

This commit is contained in:
Jade Ellis authored and Ellis Git committed 2026-11-22 17:21:50 +00:00
1 parent d477417909
commit a0d9e71eac
3 files changed
+32 -23

No files matched your search

+13 -5
View File
@@ -540,14 +540,22 @@ impl Service {
sender.send(msg).map_err(|e| err!("{e}"))
}
/// Hands the oldest unsent request of each destination to its worker, so
/// a backlog with nothing in flight is sent without waiting for a new
/// event. Bypasses `dispatch` as these requests were already counted.
/// Wakes workers for every destination that has unsent queued requests, so
/// a backlog with nothing in flight is drained without waiting for a new
/// event. Uses `SendingEvent::Flush` so a message racing with already-
/// buffered channel items cannot re-insert and duplicate a sent request.
async fn dispatch_queued(&self, shard: Option<usize>) {
for (dest, (queue_id, event)) in self.db.queued_heads().await {
for dest in self.db.queued_destinations().await {
let id = self.shard_id(&dest);
if shard.is_none_or(|shard| shard == id) {
self.channels[id].0.send(Msg { dest, event, queue_id }).ok();
self.channels[id]
.0
.send(Msg {
dest,
event: SendingEvent::Flush,
queue_id: Vec::new(),
})
.ok();
}
}
}