Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Close method for resource cleanup in graceful shutdown #16193

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,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
* (store) [#16067](https://github.com/cosmos/cosmos-sdk/pull/16067) Add local snapshots management commands.
* (server) [#16142](https://github.com/cosmos/cosmos-sdk/pull/16142) Remove JSON Indentation from the GRPC to REST gateway's responses. (Saving bandwidth)
* (baseapp) [#16193](https://github.com/cosmos/cosmos-sdk/pull/16193) Add `Close` method to `BaseApp` for custom app to cleanup resource in graceful shutdown.

### State Machine Breaking

Expand Down
5 changes: 5 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,3 +1031,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
}
4 changes: 3 additions & 1 deletion server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -260,7 +261,7 @@ func startStandAlone(svrCtx *Context, appCreator types.AppCreator) error {
// so we can gracefully stop the ABCI server.
<-ctx.Done()
svrCtx.Logger.Info("stopping the ABCI server...")
return svr.Stop()
return errors.Join(svr.Stop(), app.Close())
})

return g.Wait()
Expand Down Expand Up @@ -366,6 +367,7 @@ func startInProcess(svrCtx *Context, clientCtx client.Context, appCreator types.
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 @@ -58,6 +58,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