Skip to content

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#16204)

Co-authored-by: yihuang <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
3 people authored and roy-dydx committed Jul 11, 2023
1 parent 396359a commit 1b1ecf7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [#16068](https://github.com/cosmos/cosmos-sdk/pull/16068) Update simulation to allow non-EOA accounts to stake.
* (server) [#16142](https://github.com/cosmos/cosmos-sdk/pull/16142) Remove JSON Indentation from the GRPC to REST gateway's responses. (Saving bandwidth)
* (types) [#16145](https://github.com/cosmos/cosmos-sdk/pull/16145) Rename interface `ExtensionOptionI` back to `TxExtensionOptionI` to avoid breaking change.
* (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 @@ -1170,3 +1170,8 @@ func NoOpProcessProposal() sdk.ProcessProposalHandler {
return abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}
}
}

// Close is called in start cmd to gracefully cleanup resources.
func (app *BaseApp) Close() error {
return nil
}
6 changes: 6 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error {
fmt.Println(err.Error())
os.Exit(1)
}

if err = app.Close(); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}()

// Wait for SIGINT or SIGTERM signal
Expand Down Expand Up @@ -500,6 +505,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
defer func() {
if tmNode != nil && tmNode.IsRunning() {
_ = tmNode.Stop()
_ = app.Close()
}

if traceWriterCleanup != 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 @@ -63,6 +63,9 @@ type (

// Return the snapshot manager
SnapshotManager() *snapshots.Manager

// Close is called in start cmd to gracefully cleanup resources.
Close() error
}

// AppCreator is a function that allows us to lazily initialize an
Expand Down

0 comments on commit 1b1ecf7

Please sign in to comment.