Skip to content

Commit

Permalink
[bug] Remove invalid connection from the idle queue when request new …
Browse files Browse the repository at this point in the history
…connection (#214)

* [bug] 无效连接总数超出MaxConnPoolSize,创建session失败

[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

* [fix] go fmt

Co-authored-by: lopn <[email protected]>
  • Loading branch information
lopn and lopn authored Jul 28, 2022
1 parent f0f241c commit e8bbdaa
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e8bbdaa

Please sign in to comment.