From fcffc1a28bab990b0596ad8b66163e47a494191b Mon Sep 17 00:00:00 2001 From: Amaury <1293565+amaury1729@users.noreply.github.com> Date: Mon, 18 Dec 2023 19:07:09 +0100 Subject: [PATCH] feat(backend): Add one simple retry on Unknown --- .gitignore | 1 + backend/src/sentry_util.rs | 5 +---- backend/src/worker/check_email.rs | 16 ++++++++++++++-- core/src/util/input_output.rs | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 440529dc9..0cba1cb8d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ target **/*.rs.bk .DS_Store +private # Output when debugging Hotmail password recovery using a headless browser. hotmail.jpeg diff --git a/backend/src/sentry_util.rs b/backend/src/sentry_util.rs index 481df2d50..e1f967b21 100644 --- a/backend/src/sentry_util.rs +++ b/backend/src/sentry_util.rs @@ -99,10 +99,7 @@ fn error(err: SentryError, result: &CheckEmailOutput) { level: Level::Error, environment: Some("production".into()), release: Some(CARGO_PKG_VERSION.into()), - message: Some(redact( - format!("{result:#?}").as_str(), - &result.syntax.username, - )), + message: Some(format!("{result:#?}")), server_name: get_backend_name(), transaction: Some(format!("check_email:{}", result.syntax.domain)), ..Default::default() diff --git a/backend/src/worker/check_email.rs b/backend/src/worker/check_email.rs index 3f5b1f8fa..cfd07d342 100644 --- a/backend/src/worker/check_email.rs +++ b/backend/src/worker/check_email.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use check_if_email_exists::LOG_TARGET; use check_if_email_exists::{CheckEmailInput, CheckEmailOutput}; +use check_if_email_exists::{Reachable, LOG_TARGET}; use lapin::message::Delivery; use lapin::{options::*, BasicProperties, Channel}; use serde::{Deserialize, Serialize}; @@ -80,6 +80,8 @@ pub async fn process_check_email( debug!(target: LOG_TARGET, reply_to=?reply_to, correlation_id=?correlation_id, "Sent reply") } + let (email, is_reachable) = (output.input.to_owned(), output.is_reachable.clone()); + // Check if we have a webhook to send the output to. if let Some(webhook) = payload.webhook { let webhook_output = WebhookOutput { @@ -100,7 +102,17 @@ pub async fn process_check_email( info!(target: LOG_TARGET, email=?webhook_output.output.input, is_reachable=?webhook_output.output.is_reachable, "Finished check"); } - delivery.ack(BasicAckOptions::default()).await?; + // If is_reachable is unknown, then we requeue the message, but only once. + // We might want to add a requeue counter in the future, see: + // https://stackoverflow.com/questions/25226080/rabbitmq-how-to-requeue-message-with-counter + if is_reachable == Reachable::Unknown && !delivery.redelivered { + delivery + .reject(BasicRejectOptions { requeue: true }) + .await?; + info!(target: LOG_TARGET, email=?email, "Requeued message"); + } else { + delivery.ack(BasicAckOptions::default()).await?; + } Ok(()) } diff --git a/core/src/util/input_output.rs b/core/src/util/input_output.rs index c00c1df34..95d97b1ba 100644 --- a/core/src/util/input_output.rs +++ b/core/src/util/input_output.rs @@ -407,7 +407,7 @@ impl CheckEmailInput { /// An enum to describe how confident we are that the recipient address is /// real. -#[derive(Debug, Eq, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "lowercase")] pub enum Reachable { /// The email is safe to send.