mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
fix: 移除隧道连接时检测是否正在使用
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
_ "mayfly-go/internal/db/dbm/oracle"
|
||||
_ "mayfly-go/internal/db/dbm/postgres"
|
||||
_ "mayfly-go/internal/db/dbm/sqlite"
|
||||
"mayfly-go/internal/machine/mcm"
|
||||
"mayfly-go/pkg/logx"
|
||||
"mayfly-go/pkg/pool"
|
||||
)
|
||||
@@ -17,6 +18,25 @@ var (
|
||||
poolGroup = pool.NewPoolGroup[*dbi.DbConn]()
|
||||
)
|
||||
|
||||
func init() {
|
||||
mcm.AddCheckSshTunnelMachineUseFunc(func(machineId int) bool {
|
||||
items := poolGroup.AllPool()
|
||||
for _, v := range items {
|
||||
if v.Stats().TotalConns == 0 {
|
||||
continue // 连接池中没有连接,跳过
|
||||
}
|
||||
conn, err := v.Get(context.Background())
|
||||
if err != nil {
|
||||
continue // 获取连接失败,跳过
|
||||
}
|
||||
if conn.Info.SshTunnelMachineId == machineId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
// GetDbConn 从连接池中获取连接信息
|
||||
func GetDbConn(ctx context.Context, dbId uint64, database string, getDbInfo func() (*dbi.DbInfo, error)) (*dbi.DbConn, error) {
|
||||
connId := dbi.GetDbConnId(dbId, database)
|
||||
|
||||
Reference in New Issue
Block a user