mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
chore: adjust IMAP connection timeout configuration
This commit is contained in:
@@ -55,7 +55,7 @@ impl<E: Endpoint> Endpoint for TimeoutEndpoint<E> {
|
|||||||
|
|
||||||
async fn call(&self, req: Request) -> Result<Self::Output> {
|
async fn call(&self, req: Request) -> Result<Self::Output> {
|
||||||
let timeout = extract_timeout(&req);
|
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 {
|
match tokio::time::timeout(Duration::from_secs(seconds), self.ep.call(req)).await {
|
||||||
Ok(Ok(response)) => Ok(response), // If the request completes successfully
|
Ok(Ok(response)) => Ok(response), // If the request completes successfully
|
||||||
Ok(Err(e)) => Err(e), // If the request returns an error
|
Ok(Err(e)) => Err(e), // If the request returns an error
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ impl bb8::ManageConnection for ImapConnectionManager {
|
|||||||
pub async fn build_imap_pool(account_id: u64) -> BichonResult<Pool<ImapConnectionManager>> {
|
pub async fn build_imap_pool(account_id: u64) -> BichonResult<Pool<ImapConnectionManager>> {
|
||||||
let manager = ImapConnectionManager::new(account_id);
|
let manager = ImapConnectionManager::new(account_id);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder()
|
||||||
.connection_timeout(Duration::from_secs(30))
|
.connection_timeout(Duration::from_secs(60))
|
||||||
//.idle_timeout(Duration::from_secs(120))
|
//.idle_timeout(Duration::from_secs(120))
|
||||||
.retry_connection(true)
|
.retry_connection(true)
|
||||||
|
.queue_strategy(bb8::QueueStrategy::Fifo)
|
||||||
.max_size(10)
|
.max_size(10)
|
||||||
.test_on_check_out(true)
|
.test_on_check_out(true)
|
||||||
.build(manager)
|
.build(manager)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ use tokio_io_timeout::TimeoutStream;
|
|||||||
use tokio_socks::tcp::Socks5Stream;
|
use tokio_socks::tcp::Socks5Stream;
|
||||||
use tracing::error;
|
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(
|
pub(crate) async fn establish_tcp_connection_with_timeout(
|
||||||
address: SocketAddr,
|
address: SocketAddr,
|
||||||
@@ -39,17 +39,17 @@ pub(crate) async fn establish_tcp_connection_with_timeout(
|
|||||||
// Establish the TCP connection with a timeout
|
// Establish the TCP connection with a timeout
|
||||||
let tcp_stream = connect_with_optional_proxy(use_proxy, address).await?;
|
let tcp_stream = connect_with_optional_proxy(use_proxy, address).await?;
|
||||||
|
|
||||||
// Disable Nagle's algorithm for more efficient network communication
|
// // Disable Nagle's algorithm for more efficient network communication
|
||||||
tcp_stream
|
// tcp_stream
|
||||||
.set_nodelay(true)
|
// .set_nodelay(true)
|
||||||
.map_err(|e| raise_error!(e.to_string(), ErrorCode::NetworkError))?;
|
// .map_err(|e| raise_error!(e.to_string(), ErrorCode::NetworkError))?;
|
||||||
|
|
||||||
// Wrap the TCP stream in a TimeoutStream for timeout management
|
// Wrap the TCP stream in a TimeoutStream for timeout management
|
||||||
let mut timeout_stream = TimeoutStream::new(tcp_stream);
|
let mut timeout_stream = TimeoutStream::new(tcp_stream);
|
||||||
|
|
||||||
// Set read and write timeouts
|
// Set read and write timeouts
|
||||||
timeout_stream.set_write_timeout(Some(TIMEOUT));
|
timeout_stream.set_write_timeout(Some(Duration::from_secs(15)));
|
||||||
timeout_stream.set_read_timeout(Some(TIMEOUT));
|
timeout_stream.set_read_timeout(Some(Duration::from_secs(30)));
|
||||||
|
|
||||||
// Return the timeout-wrapped TCP stream as a Pin
|
// Return the timeout-wrapped TCP stream as a Pin
|
||||||
Ok(Box::pin(timeout_stream))
|
Ok(Box::pin(timeout_stream))
|
||||||
|
|||||||
Reference in New Issue
Block a user