From 1b85614db93b622fa6546e2ea7b8b33f2801e522 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 10 Dec 2023 00:55:23 +0000 Subject: [PATCH] fix: renew IDLE timeout on keepalives and reduce it to 5 minutes This change depends on async-imap update that resets the timeout every time an `* OK Still here` is received. Reducing timeout allows to detect lost connections not later than 6 minutes because Delta Chat will attempt to finish IDLE with DONE after 5 minutes without keepalives and will either get TCP RST directly or, worst case, wait another minute for TCP socket read timeout. --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/imap/idle.rs | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b25b8f392..46922620e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -224,9 +224,9 @@ dependencies = [ [[package]] name = "async-imap" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d736a74edf6c327b53dd9c932eae834253470ac5f0c55770e7e133bcbf986362" +checksum = "a9d69fc1499878158750f644c4eb46aff55bb9d32d77e3dc4aecf8308d5c3ba6" dependencies = [ "async-channel 2.1.1", "base64 0.21.5", diff --git a/Cargo.toml b/Cargo.toml index 72d8e46d7..82f20b1b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ ratelimit = { path = "./deltachat-ratelimit" } anyhow = "1" async-channel = "2.0.0" -async-imap = { version = "0.9.1", default-features = false, features = ["runtime-tokio"] } +async-imap = { version = "0.9.5", default-features = false, features = ["runtime-tokio"] } async-native-tls = { version = "0.5", default-features = false, features = ["runtime-tokio"] } async-smtp = { version = "0.9", default-features = false, features = ["runtime-tokio"] } async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] } diff --git a/src/imap/idle.rs b/src/imap/idle.rs index 5025ed21e..6fcb768e2 100644 --- a/src/imap/idle.rs +++ b/src/imap/idle.rs @@ -12,7 +12,13 @@ use crate::context::Context; use crate::imap::{client::IMAP_TIMEOUT, FolderMeaning}; use crate::log::LogExt; -const IDLE_TIMEOUT: Duration = Duration::from_secs(23 * 60); +/// Timeout after which IDLE is finished +/// if there are no responses from the server. +/// +/// If `* OK Still here` keepalives are sent more frequently +/// than this duration, timeout should never be triggered. +/// For example, Dovecot sends keepalives every 2 minutes by default. +const IDLE_TIMEOUT: Duration = Duration::from_secs(5 * 60); impl Session { pub async fn idle(