Skip to content

Commit

Permalink
Leandro/close admin db connection (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrorichardtoledo authored Oct 31, 2024
1 parent 31bd8f1 commit 414be96
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/dbclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dbclient
import (
"context"
"database/sql"
"errors"
"fmt"
"net/url"
"strings"
Expand Down Expand Up @@ -961,11 +962,24 @@ func (pc *client) RevokeAccessToRole(username, rolename string) error {
}

func (pc *client) Close() error {
var errs []error

if pc.DB != nil {
return pc.DB.Close()
if dbErr := pc.DB.Close(); dbErr != nil {
pc.log.Error(dbErr, "could not close DB")
errs = append(errs, fmt.Errorf("could not user client conn: %w", dbErr))
}
}

if pc.adminDB != nil {
if adminErr := pc.adminDB.Close(); adminErr != nil {
pc.log.Error(adminErr, "could not close admin DB")
errs = append(errs, adminErr)
}
}

return fmt.Errorf("can't close nil DB")
// This will be nil if all errs are nil
return errors.Join(errs...)
}

func escapeValue(in string) string {
Expand Down

0 comments on commit 414be96

Please sign in to comment.