Skip to content

Commit

Permalink
Handle db close errors (#1370)
Browse files Browse the repository at this point in the history
  • Loading branch information
InverseIntegral authored Jan 10, 2025
1 parent a77e0c5 commit 74989fe
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions library/oss/postgres/prepare/database/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func main() {
if err != nil {
log.Fatalf("unable to open connection: %v", err)
}
defer db.Close()
defer func() {
if err := db.Close(); err != nil {
log.Printf("unable to close database connection: %v", err)
}
}()

for _, schema := range p.Intent.Schema {
if _, err := universepg.ReturnFromReadWriteTx(ctx, db, backOff{
Expand All @@ -99,7 +103,11 @@ func ensureDatabase(ctx context.Context, cluster *postgresclass.ClusterInstance,
if err != nil {
return false, err
}
defer postgresConn.Close(ctx)
defer func() {
if err := postgresConn.Close(ctx); err != nil {
log.Printf("unable to close database connection: %v", err)
}
}()

exists, err := existsDatabase(ctx, postgresConn, name)
if err != nil {
Expand Down

0 comments on commit 74989fe

Please sign in to comment.