From c207b88b3acaa584b38e5f27ad9ceb6e1a56e9f9 Mon Sep 17 00:00:00 2001 From: Nick Hill Date: Tue, 2 May 2023 12:53:13 +0100 Subject: [PATCH] small change to handling of cancelled requests --- router/src/queue.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/router/src/queue.rs b/router/src/queue.rs index 4084eb6c..322fc6b4 100644 --- a/router/src/queue.rs +++ b/router/src/queue.rs @@ -332,11 +332,10 @@ impl State { self.last_seen_batch_size = total_count } - // Filter entries where the response receiver was dropped (== entries where the request - // was dropped by the client) - let queue_len_before = self.entries.len(); - self.entries.retain_mut(|(_, entry)| !entry.response_tx.is_disconnected()); - if queue_len_before != self.entries.len() { + // Filter cancelled entries from the front of the queue, + // so that next-entry waiting time is accurate + while matches!(self.entries.front(), Some((_,entry)) if entry.response_tx.is_disconnected()) { + self.entries.pop_front(); // Reset the count of checked requests if any in the queue were cancelled since last check self.checked_request_count = 0; } @@ -354,7 +353,7 @@ impl State { } } - // Indices into buffer of entries chosen to add to next batch or remove due to expiry + // Indices into buffer of entries chosen to add to next batch let mut chosen_indices = vec![]; // Indices to drop due to client cancellation let mut indices_to_drop = vec![];