Skip to content

Commit

Permalink
main: Defer database close.
Browse files Browse the repository at this point in the history
This defers the database close once opened to ensure it is always
properly closed on all error paths.

It also adds a defer for the overall shutdown complete message and
updates the hub shutdown complete message to indicate it's referring to
the hub.
  • Loading branch information
davecgh committed Sep 12, 2023
1 parent 7344dcc commit 805ff82
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dcrpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func realMain() error {
logRotator.Close()
}
}()
defer mpLog.Info("Shutdown complete")

var db pool.Database
if cfg.UsePostgres {
Expand All @@ -170,11 +171,11 @@ func realMain() error {
} else {
db, err = pool.InitBoltDB(cfg.DBFile)
}

if err != nil {
mpLog.Errorf("failed to initialize database: %v", err)
return err
}
defer db.Close()

p, err := newPool(db, cfg)
if err != nil {
Expand Down Expand Up @@ -226,8 +227,7 @@ func realMain() error {
}
}

db.Close()
mpLog.Info("dcrpool shut down.")
mpLog.Info("Hub shutdown complete")
return nil
}

Expand Down

0 comments on commit 805ff82

Please sign in to comment.