From 5194c11d90d267af596e0644e9e754792a4f004b Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Tue, 12 Oct 2021 20:52:10 +0200 Subject: [PATCH] Use unbounded channel --- src/hooker.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/hooker.rs b/src/hooker.rs index 7713dec3..c53f86a0 100644 --- a/src/hooker.rs +++ b/src/hooker.rs @@ -6,11 +6,11 @@ use crate::models::user::User; use askama::Template; use lettre::message::Mailbox; use rocket::tokio::sync::mpsc; -use rocket::tokio::sync::mpsc::Receiver; +use rocket::tokio::sync::mpsc::UnboundedReceiver; #[derive(Clone)] pub struct Hooker { - queue: mpsc::Sender, + queue: mpsc::UnboundedSender, } impl Hooker { @@ -19,7 +19,9 @@ impl Hooker { mailer: &Mailer, admin_email: &AdminEmail, ) -> Result { - let (sender, recv) = mpsc::channel(5); // TODO(chvp): actual size limit + // Webhooks are only triggered by admin actions, so no need to worry + // about abuse + let (sender, recv) = mpsc::unbounded_channel(); if let Some(url) = &config.webhook_url { rocket::tokio::spawn(Self::http_sender( @@ -38,12 +40,11 @@ impl Hooker { pub async fn user_approved(&self, user: &User) -> Result<()> { self.queue .send(user.clone()) - .await .map_err(|e| ZauthError::from(InternalError::from(e))) } fn stub_sender( - mut receiver: Receiver, + mut receiver: UnboundedReceiver, ) -> impl std::future::Future { async move { // no URL configured, so we just drop the received users @@ -53,7 +54,7 @@ impl Hooker { fn http_sender( url: String, - mut receiver: Receiver, + mut receiver: UnboundedReceiver, admin_email: Mailbox, mailer: Mailer, ) -> impl std::future::Future {