forked from cerc-io/laconicd-deprecated
server: add missing db.Close calls before returning (#541)
It's better to always close the db before exit, so we will be noticed when any error happens. Otherwise, serious errors can silently happen, e.g, corrupted db, pending write missing ... Fixes #538
This commit is contained in:
@@ -164,6 +164,11 @@ func startStandAlone(ctx *server.Context, appCreator types.AppCreator) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := db.Close(); err != nil {
|
||||
ctx.Logger.With("error", err).Error("error closing db")
|
||||
}
|
||||
}()
|
||||
|
||||
traceWriterFile := ctx.Viper.GetString(srvflags.TraceStore)
|
||||
traceWriter, err := openTraceWriter(traceWriterFile)
|
||||
@@ -226,6 +231,11 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
|
||||
logger.Error("failed to open DB", "error", err.Error())
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := db.Close(); err != nil {
|
||||
ctx.Logger.With("error", err).Error("error closing db")
|
||||
}
|
||||
}()
|
||||
|
||||
traceWriter, err := openTraceWriter(traceWriterFile)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user