Skip to content

Commit

Permalink
refactor(network): call app.Close() on network cleanup (backport #1…
Browse files Browse the repository at this point in the history
…8249) (#18251)

Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
mergify[bot] and julienrbrt authored Oct 25, 2023
1 parent 98a8bfe commit af758d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 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/

### Bug Fixes

* (server) [#18251](https://github.com/cosmos/cosmos-sdk/pull/18251) Call `baseapp.Close()` when app started as grpc only.
* (baseapp) [#17769](https://github.com/cosmos/cosmos-sdk/pull/17769) Ensure we respect block size constraints in the `DefaultProposalHandler`'s `PrepareProposal` handler when a nil or no-op mempool is used. We provide a `TxSelector` type to assist in making transaction selection generalized. We also fix a comparison bug in tx selection when `req.maxTxBytes` is reached.
* (config) [#17649](https://github.com/cosmos/cosmos-sdk/pull/17649) Fix `mempool.max-txs` configuration is invalid in `app.config`.
* (mempool) [#17668](https://github.com/cosmos/cosmos-sdk/pull/17668) Fix `PriorityNonceIterator.Next()` nil pointer ref for min priority at the end of iteration.
Expand Down
36 changes: 18 additions & 18 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ func startStandAlone(ctx *Context, clientCtx client.Context, appCreator types.Ap

defer func() {
_ = svr.Stop()

_ = app.Close()

if apiSrv != nil {
Expand Down Expand Up @@ -437,6 +436,24 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
}

defer func() {
if tmNode != nil && tmNode.IsRunning() {
_ = tmNode.Stop()
}

if traceWriterCleanup != nil {
traceWriterCleanup()
}

_ = app.Close()

if apiSrv != nil {
_ = apiSrv.Close()
}

ctx.Logger.Info("exiting...")
}()

// At this point it is safe to block the process if we're in gRPC only mode as
// we do not need to start Rosetta or handle any Tendermint related processes.
if gRPCOnly {
Expand Down Expand Up @@ -494,23 +511,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App
}
}

defer func() {
if tmNode != nil && tmNode.IsRunning() {
_ = tmNode.Stop()
_ = app.Close()
}

if traceWriterCleanup != nil {
traceWriterCleanup()
}

if apiSrv != nil {
_ = apiSrv.Close()
}

ctx.Logger.Info("exiting...")
}()

// wait for signal capture and gracefully return
return WaitForQuitSignals()
}
Expand Down
10 changes: 8 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ type (
ValAddress sdk.ValAddress
RPCClient tmclient.Client

app servertypes.Application
tmNode *node.Node
api *api.Server
grpc *grpc.Server
Expand Down Expand Up @@ -581,8 +582,7 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {

l.Log("starting test network...")
for idx, v := range network.Validators {
err := startInProcess(cfg, v)
if err != nil {
if err := startInProcess(cfg, v); err != nil {
return nil, err
}
l.Log("started validator", idx)
Expand Down Expand Up @@ -734,6 +734,12 @@ func (n *Network) Cleanup() {
_ = v.grpcWeb.Close()
}
}

if v.app != nil {
if err := v.app.Close(); err != nil {
n.Logger.Log("failed to stop validator ABCI application", "err", err)
}
}
}

// Give a brief pause for things to finish closing in other processes. Hopefully this helps with the address-in-use errors.
Expand Down
1 change: 1 addition & 0 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func startInProcess(cfg Config, val *Validator) error {
}

app := cfg.AppConstructor(*val)
val.app = app
genDocProvider := node.DefaultGenesisDocProviderFunc(tmCfg)

tmNode, err := node.NewNode( //resleak:notresource
Expand Down

0 comments on commit af758d7

Please sign in to comment.