From b5c03814471a6229a8d4a405ba5f0089a0dff7fc Mon Sep 17 00:00:00 2001 From: Oussama Gammoudi Date: Fri, 20 May 2022 16:25:36 +0200 Subject: [PATCH 1/2] cancel connection when acquired by binlog_stream --- src/conn/mod.rs | 2 +- src/conn/pool/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conn/mod.rs b/src/conn/mod.rs index 436afff6..bcfad82e 100644 --- a/src/conn/mod.rs +++ b/src/conn/mod.rs @@ -1032,7 +1032,7 @@ impl Conn { pub async fn get_binlog_stream(mut self, request: BinlogRequest<'_>) -> Result { // We'll disconnect this connection from a pool before requesting the binlog. - self.inner.pool = None; + self.inner.pool.take().map(|pool|pool.cancel_connection()); self.request_binlog(request).await?; Ok(BinlogStream::new(self)) diff --git a/src/conn/pool/mod.rs b/src/conn/pool/mod.rs index ffbc2b89..55a34d59 100644 --- a/src/conn/pool/mod.rs +++ b/src/conn/pool/mod.rs @@ -221,7 +221,7 @@ impl Pool { /// /// Decreases the exist counter since a broken or dropped connection should not count towards /// the total. - fn cancel_connection(&self) { + pub(super) fn cancel_connection(&self) { let mut exchange = self.inner.exchange.lock().unwrap(); exchange.exist -= 1; // we just enabled the creation of a new connection! From 11b0ef904baf58f0fd8a179c1df46cfb7c5207c9 Mon Sep 17 00:00:00 2001 From: galeaspablo Date: Sun, 22 May 2022 11:35:12 +0100 Subject: [PATCH 2/2] Cargo fmt --- src/conn/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conn/mod.rs b/src/conn/mod.rs index bcfad82e..f1f64cb0 100644 --- a/src/conn/mod.rs +++ b/src/conn/mod.rs @@ -1032,7 +1032,7 @@ impl Conn { pub async fn get_binlog_stream(mut self, request: BinlogRequest<'_>) -> Result { // We'll disconnect this connection from a pool before requesting the binlog. - self.inner.pool.take().map(|pool|pool.cancel_connection()); + self.inner.pool.take().map(|pool| pool.cancel_connection()); self.request_binlog(request).await?; Ok(BinlogStream::new(self))