chore: adjust IMAP connection timeout configuration

This commit is contained in:
rustmailer
2026-01-28 13:20:09 +08:00
parent fed28c3eca
commit bdbbc04832
3 changed files with 10 additions and 9 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ impl<E: Endpoint> Endpoint for TimeoutEndpoint<E> {
async fn call(&self, req: Request) -> Result<Self::Output> {
let timeout = extract_timeout(&req);
let seconds = timeout.unwrap_or(30).min(600);
let seconds = timeout.unwrap_or(60).min(600);
match tokio::time::timeout(Duration::from_secs(seconds), self.ep.call(req)).await {
Ok(Ok(response)) => Ok(response), // If the request completes successfully
Ok(Err(e)) => Err(e), // If the request returns an error
+2 -1
View File
@@ -47,9 +47,10 @@ impl bb8::ManageConnection for ImapConnectionManager {
pub async fn build_imap_pool(account_id: u64) -> BichonResult<Pool<ImapConnectionManager>> {
let manager = ImapConnectionManager::new(account_id);
let pool = Pool::builder()
.connection_timeout(Duration::from_secs(30))
.connection_timeout(Duration::from_secs(60))
//.idle_timeout(Duration::from_secs(120))
.retry_connection(true)
.queue_strategy(bb8::QueueStrategy::Fifo)
.max_size(10)
.test_on_check_out(true)
.build(manager)
+7 -7
View File
@@ -30,7 +30,7 @@ use tokio_io_timeout::TimeoutStream;
use tokio_socks::tcp::Socks5Stream;
use tracing::error;
pub(crate) const TIMEOUT: Duration = Duration::from_secs(60);
pub(crate) const TIMEOUT: Duration = Duration::from_secs(30);
pub(crate) async fn establish_tcp_connection_with_timeout(
address: SocketAddr,
@@ -39,17 +39,17 @@ pub(crate) async fn establish_tcp_connection_with_timeout(
// Establish the TCP connection with a timeout
let tcp_stream = connect_with_optional_proxy(use_proxy, address).await?;
// Disable Nagle's algorithm for more efficient network communication
tcp_stream
.set_nodelay(true)
.map_err(|e| raise_error!(e.to_string(), ErrorCode::NetworkError))?;
// // Disable Nagle's algorithm for more efficient network communication
// tcp_stream
// .set_nodelay(true)
// .map_err(|e| raise_error!(e.to_string(), ErrorCode::NetworkError))?;
// Wrap the TCP stream in a TimeoutStream for timeout management
let mut timeout_stream = TimeoutStream::new(tcp_stream);
// Set read and write timeouts
timeout_stream.set_write_timeout(Some(TIMEOUT));
timeout_stream.set_read_timeout(Some(TIMEOUT));
timeout_stream.set_write_timeout(Some(Duration::from_secs(15)));
timeout_stream.set_read_timeout(Some(Duration::from_secs(30)));
// Return the timeout-wrapped TCP stream as a Pin
Ok(Box::pin(timeout_stream))