From 63d2ff054c94acca57604c1239fc9e2883eb0597 Mon Sep 17 00:00:00 2001 From: lopn Date: Fri, 22 Jul 2022 13:07:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[bug]=20=E6=97=A0=E6=95=88=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=80=BB=E6=95=B0=E8=B6=85=E5=87=BAMaxConnPoolSize?= =?UTF-8?q?=EF=BC=8C=E5=88=9B=E5=BB=BAsession=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [bug] 移除无效连接 ,防止由于无效连接导致 连接总数超出MaxConnPoolSize,导致创建session失败 Fail to create a new session from connection pool, username: root, password: nebula, failed to get connection: No valid connection in the idle queue and connection number has reached the pool capacity --- connection_pool.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connection_pool.go b/connection_pool.go index cf1cb63b..440f35c1 100644 --- a/connection_pool.go +++ b/connection_pool.go @@ -144,12 +144,16 @@ func (pool *ConnectionPool) getIdleConn() (*connection, error) { if pool.idleConnectionQueue.Len() > 0 { var newConn *connection = nil var newEle *list.Element = nil - for ele := pool.idleConnectionQueue.Front(); ele != nil; ele = ele.Next() { + var tmpNextEle *list.Element = nil + for ele := pool.idleConnectionQueue.Front(); ele != nil; ele = tmpNextEle { // Check if connection is valid if res := ele.Value.(*connection).ping(); res { newConn = ele.Value.(*connection) newEle = ele break + }else{ + tmpNextEle = ele.Next() + pool.idleConnectionQueue.Remove(ele) } } if newConn == nil { From 652c0b5c0d73533acbce01ad5728756b68289baa Mon Sep 17 00:00:00 2001 From: lopn Date: Thu, 28 Jul 2022 15:52:46 +0800 Subject: [PATCH 2/2] [fix] go fmt --- connection_pool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connection_pool.go b/connection_pool.go index 440f35c1..57a65c05 100644 --- a/connection_pool.go +++ b/connection_pool.go @@ -151,7 +151,7 @@ func (pool *ConnectionPool) getIdleConn() (*connection, error) { newConn = ele.Value.(*connection) newEle = ele break - }else{ + } else { tmpNextEle = ele.Next() pool.idleConnectionQueue.Remove(ele) }