Skip to content

Commit aba68f7

Browse files
committed
fix: ensure testnetApp cleanup on error in testnetify
Signed-off-by: Evan Etton <[email protected]>
1 parent 7e9ad4f commit aba68f7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

server/start.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,24 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
816816
ctx.Viper.Set(KeyUserPubKey, userPubKey)
817817
testnetApp := testnetAppCreator(ctx.Logger, db, traceWriter, ctx.Viper)
818818

819+
var success bool
820+
defer func() {
821+
if !success {
822+
if err := testnetApp.Close(); err != nil {
823+
ctx.Logger.Error("failed to close testnet app on error", "err", err)
824+
}
825+
}
826+
}()
827+
828+
var success bool
829+
defer func() {
830+
if !success {
831+
if err := testnetApp.Close(); err != nil {
832+
ctx.Logger.Error("failed to close testnet app on error", "err", err)
833+
}
834+
}
835+
}()
836+
819837
// We need to create a temporary proxyApp to get the initial state of the application.
820838
// Depending on how the node was stopped, the application height can differ from the blockStore height.
821839
// This height difference changes how we go about modifying the state.
@@ -975,7 +993,9 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
975993
return nil, err
976994
}
977995

978-
return testnetApp, err
996+
success = true
997+
return testnetApp, nil
998+
}
979999
}
9801000

9811001
// addStartNodeFlags should be added to any CLI commands that start the network.

0 commit comments

Comments
 (0)