diff --git a/src/bot.rs b/src/bot.rs index b3cf700..56cd999 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -61,6 +61,14 @@ impl Bot { let mut tasks = tokio::task::JoinSet::new(); while let Some(wb) = rx.recv().await { + // Drain completed tasks to avoid the JoinSet growing unbounded + while let Some(res) = tasks.try_join_next() { + if let Err(e) = res { + error!("Task panicked: {e}"); + } + } + + info!(queued = rx.len(), active = tasks.len(), "Webhook received"); let permit = sem.clone().acquire_owned().await?; let self_clone = self.clone(); @@ -70,8 +78,8 @@ impl Bot { }); } - // Le channel est fermé : on attend que les tâches en cours se terminent - // proprement avant de rendre la main + // When all webhook tasks have completed, we can safely exit + // properly before returning while let Some(res) = tasks.join_next().await { if let Err(e) = res { error!("Task panicked: {e}");