Skip to content

Commit 936a37e

Browse files
authored
fix: ensure testnetApp cleanup on error in testnetify (#25660)
Signed-off-by: Evan Etton <[email protected]>
1 parent 7e9ad4f commit 936a37e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

server/start.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,15 @@ 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+
819828
// We need to create a temporary proxyApp to get the initial state of the application.
820829
// Depending on how the node was stopped, the application height can differ from the blockStore height.
821830
// This height difference changes how we go about modifying the state.
@@ -975,7 +984,8 @@ func testnetify(ctx *Context, testnetAppCreator types.AppCreator, db dbm.DB, tra
975984
return nil, err
976985
}
977986

978-
return testnetApp, err
987+
success = true
988+
return testnetApp, nil
979989
}
980990

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

0 commit comments

Comments
 (0)