feat(transport-smtp): Call conn.quit() when pooled conns are released (#559)
* Implement CustomizeConnection::on_release() for SmtpConnection
This commit is contained in:
@@ -2,7 +2,7 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use crate::transport::smtp::{client::SmtpConnection, error::Error, SmtpClient};
|
use crate::transport::smtp::{client::SmtpConnection, error::Error, SmtpClient};
|
||||||
|
|
||||||
use r2d2::{ManageConnection, Pool};
|
use r2d2::{CustomizeConnection, ManageConnection, Pool};
|
||||||
|
|
||||||
/// Configuration for a connection pool
|
/// Configuration for a connection pool
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@@ -53,12 +53,16 @@ impl PoolConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn build<C: ManageConnection>(&self, client: C) -> Pool<C> {
|
pub(crate) fn build<C: ManageConnection<Connection = SmtpConnection, Error = Error>>(
|
||||||
|
&self,
|
||||||
|
client: C,
|
||||||
|
) -> Pool<C> {
|
||||||
Pool::builder()
|
Pool::builder()
|
||||||
.min_idle(Some(self.min_idle))
|
.min_idle(Some(self.min_idle))
|
||||||
.max_size(self.max_size)
|
.max_size(self.max_size)
|
||||||
.connection_timeout(self.connection_timeout)
|
.connection_timeout(self.connection_timeout)
|
||||||
.idle_timeout(Some(self.idle_timeout))
|
.idle_timeout(Some(self.idle_timeout))
|
||||||
|
.connection_customizer(Box::new(SmtpConnectionQuitter))
|
||||||
.build_unchecked(client)
|
.build_unchecked(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,3 +97,15 @@ impl ManageConnection for SmtpClient {
|
|||||||
conn.has_broken()
|
conn.has_broken()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
struct SmtpConnectionQuitter;
|
||||||
|
|
||||||
|
impl CustomizeConnection<SmtpConnection, Error> for SmtpConnectionQuitter {
|
||||||
|
fn on_release(&self, conn: SmtpConnection) {
|
||||||
|
let mut conn = conn;
|
||||||
|
if !conn.has_broken() {
|
||||||
|
let _quit = conn.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user