From 4e5e9f60065f2b9f9eede80996076205cb33f105 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Wed, 6 Nov 2024 17:29:02 -0300 Subject: [PATCH] fix: send_msg_to_smtp: Return Ok if `smtp` row is deleted in parallel Follow-up to ded8c02c0f0bc220800877200b1587678f0188c6. `smtp` rows may be deleted in parallel, in this case there's just nothing to send. --- src/chat.rs | 1 + src/smtp.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 9d36f30d8..e33a7d7a5 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4505,6 +4505,7 @@ pub(crate) async fn delete_and_reset_all_device_msgs(context: &Context) -> Resul /// Adds an informational message to chat. /// /// For example, it can be a message showing that a member was added to a group. +/// Doesn't fail if the chat doesn't exist. #[allow(clippy::too_many_arguments)] pub(crate) async fn add_info_msg_with_cmd( context: &Context, diff --git a/src/smtp.rs b/src/smtp.rs index 0c1bd33d7..406253e20 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -357,9 +357,9 @@ pub(crate) async fn send_msg_to_smtp( .await .context("failed to update retries count")?; - let (body, recipients, msg_id, retries) = context + let Some((body, recipients, msg_id, retries)) = context .sql - .query_row( + .query_row_optional( "SELECT mime, recipients, msg_id, retries FROM smtp WHERE id=?", (rowid,), |row| { @@ -370,7 +370,10 @@ pub(crate) async fn send_msg_to_smtp( Ok((mime, recipients, msg_id, retries)) }, ) - .await?; + .await? + else { + return Ok(()); + }; if retries > 6 { if let Some(mut msg) = Message::load_from_db_optional(context, msg_id).await? { message::set_msg_failed(context, &mut msg, "Number of retries exceeded the limit.")