diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca726fd72a6..27d224d77100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (gov) [#15979](https://github.com/cosmos/cosmos-sdk/pull/15979) Improve gov error message when failing to convert v1 proposal to v1beta1. * (server) [#16061](https://github.com/cosmos/cosmos-sdk/pull/16061) add comet bootstrap command * (store) [#16067](https://github.com/cosmos/cosmos-sdk/pull/16067) Add local snapshots management commands. +* (baseapp) [#16193](https://github.com/cosmos/cosmos-sdk/pull/16193) Add `Close` method to `BaseApp` for custom app to cleanup resource in graceful shutdown. ### Bug Fixes diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 98c2f226a059..ca2fe852af6e 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -844,3 +844,8 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s func makeABCIData(msgResponses []*codectypes.Any) ([]byte, error) { return proto.Marshal(&sdk.TxMsgData{MsgResponses: msgResponses}) } + +// Close is called in start cmd to gracefully cleanup resources. +func (app *BaseApp) Close() error { + return nil +} diff --git a/server/start.go b/server/start.go index 208bfb8db674..2ea63c5fe1a9 100644 --- a/server/start.go +++ b/server/start.go @@ -244,6 +244,10 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error { if err = svr.Stop(); err != nil { tmos.Exit(err.Error()) } + + if err = app.Close(); err != nil { + tmos.Exit(err.Error()) + } }() // Wait for SIGINT or SIGTERM signal @@ -485,6 +489,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App defer func() { if tmNode != nil && tmNode.IsRunning() { _ = tmNode.Stop() + _ = app.Close() } if apiSrv != nil { diff --git a/server/types/app.go b/server/types/app.go index 124dcf4c25ad..d886936f75c5 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -59,6 +59,9 @@ type ( // Return the snapshot manager SnapshotManager() *snapshots.Manager + + // Close is called in start cmd to gracefully cleanup resources. + Close() error } // ApplicationQueryService defines an extension of the Application interface