Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
feat: add Close method for resource cleanup in graceful shutdown (bac…
Browse files Browse the repository at this point in the history
…kport cosmos#16193) (cosmos#16205)

Co-authored-by: yihuang <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored May 19, 2023
1 parent 5472fb5 commit 557da6e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions server/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 557da6e

Please sign in to comment.