Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(hive): avoid dead lock if err (#12476)

Azusain80b3c30356c0
diff --git a/backend/plugin/db/hive/hive.go b/backend/plugin/db/hive/hive.go
index 47543718a1..61fe2b21dd 100644
--- a/backend/plugin/db/hive/hive.go
+++ b/backend/plugin/db/hive/hive.go
@@ -73,8 +73,19 @@ func (d *Driver) Open(_ context.Context, _ storepb.Engine, config db.ConnectionC
newConn, err := d.connPool.Get(config.Database)
if err != nil {
- return nil, errors.New("failed to get connection from pool")
+ err = errors.Wrapf(err, "failed to get connection from pool")
+ // release resources.
+ if errClose := func() error {
+ if err := newConn.Close(); err != nil {
+ return err
+ }
+ return d.connPool.Destroy()
+ }(); errClose != nil {
+ return nil, errors.Wrapf(err, "failed to release resources")
+ }
+ return nil, err
}
+
d.conn = newConn
return d, nil
diff --git a/backend/plugin/db/hive/hive_conn_pool.go b/backend/plugin/db/hive/hive_conn_pool.go
index 09dbea1f13..15e76fea97 100644
--- a/backend/plugin/db/hive/hive_conn_pool.go
+++ b/backend/plugin/db/hive/hive_conn_pool.go
@@ -85,6 +85,7 @@ func CreateHiveConnPool(
func (pool *FixedConnPool) Get(dbName string) (*gohive.Connection, error) {
pool.RWMutex.RLock()
if !pool.IsActivated {
+ pool.RWMutex.RUnlock()
return nil, errors.New("connection pool has been closed")
}
pool.RWMutex.RUnlock()
@@ -117,6 +118,7 @@ func (pool *FixedConnPool) Put(conn *gohive.Connection) {
pool.RWMutex.RLock()
if !pool.IsActivated {
conn.Close()
+ pool.RWMutex.RUnlock()
return
}
pool.RWMutex.RUnlock()
@@ -130,10 +132,12 @@ func (pool *FixedConnPool) Put(conn *gohive.Connection) {
func (pool *FixedConnPool) Destroy() error {
pool.RWMutex.Lock()
+
if pool.IsActivated {
pool.IsActivated = false
close(pool.Connections)
} else {
+ pool.RWMutex.Unlock()
return errors.New("connection pool has been closed already")
}
pool.RWMutex.Unlock()