From 89a7c9fbfb4ae69007432524aeccb570273c0f4b Mon Sep 17 00:00:00 2001 From: Tim Vilgot Mikael Fredenberg Date: Fri, 24 Oct 2025 17:35:38 +0200 Subject: [PATCH] perf(http-ratelimiting): drop stale requests early --- twilight-http-ratelimiting/src/actor.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/twilight-http-ratelimiting/src/actor.rs b/twilight-http-ratelimiting/src/actor.rs index 5eedd170c2..56b07cb160 100644 --- a/twilight-http-ratelimiting/src/actor.rs +++ b/twilight-http-ratelimiting/src/actor.rs @@ -221,6 +221,7 @@ pub async fn runner( old_queue.in_flight = false; let (pending, old_pending) = mem::take(&mut old_queue.pending) .into_iter() + .filter(|req| !req.notifier.is_closed()) .partition::, _>(|req| req.endpoint == *old_entry.key()); old_queue.pending = old_pending; try_pop!(old_queue); @@ -284,6 +285,10 @@ pub async fn runner( } } Some((msg, pred)) = rx.recv() => { + if msg.notifier.is_closed() { + continue; + } + if !msg.endpoint.is_valid() { tracing::warn!(path = msg.endpoint.path, "improperly formatted path"); } @@ -312,7 +317,7 @@ pub async fn runner( drop(msg); } else if queue_active || (global_remaining == 0 && !msg.endpoint.is_interaction()) { queue.pending.push_back(msg); - } else if !msg.notifier.is_closed() { + } else { let (tx, rx) = oneshot::channel(); if msg.notifier.send(tx).is_ok() { tracing::debug!(path = msg.endpoint.path, "permitted");