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

refactor(network): call app.Close() on network cleanup (backport #18249) #18250

Merged
merged 1 commit into from
Oct 25, 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
10 changes: 8 additions & 2 deletions testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type (
ValAddress sdk.ValAddress
RPCClient cmtclient.Client

app servertypes.Application
tmNode *node.Node
api *api.Server
grpc *grpc.Server
Expand Down Expand Up @@ -611,8 +612,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 @@ -803,6 +803,12 @@ func (n *Network) Cleanup() {
if v.grpcWeb != nil {
_ = 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)
}
}
}

time.Sleep(100 * time.Millisecond)
Expand Down
8 changes: 6 additions & 2 deletions testutil/network/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
cmttime "github.com/cometbft/cometbft/types/time"
"golang.org/x/sync/errgroup"

"cosmossdk.io/log"

"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/api"
servergrpc "github.com/cosmos/cosmos-sdk/server/grpc"
Expand All @@ -43,6 +45,8 @@ func startInProcess(cfg Config, val *Validator) error {
}

app := cfg.AppConstructor(*val)
val.app = app

appGenesisProvider := func() (*cmttypes.GenesisDoc, error) {
appGenesis, err := genutiltypes.AppGenesisFromFile(cmtCfg.GenesisFile())
if err != nil {
Expand Down Expand Up @@ -101,14 +105,14 @@ func startInProcess(cfg Config, val *Validator) error {
// Start the gRPC server in a goroutine. Note, the provided ctx will ensure
// that the server is gracefully shut down.
val.errGroup.Go(func() error {
return servergrpc.StartGRPCServer(ctx, logger.With("module", "grpc-server"), grpcCfg, grpcSrv)
return servergrpc.StartGRPCServer(ctx, logger.With(log.ModuleKey, "grpc-server"), grpcCfg, grpcSrv)
})

val.grpc = grpcSrv
}

if val.APIAddress != "" {
apiSrv := api.New(val.ClientCtx, logger.With("module", "api-server"), val.grpc)
apiSrv := api.New(val.ClientCtx, logger.With(log.ModuleKey, "api-server"), val.grpc)
app.RegisterAPIRoutes(apiSrv, val.AppConfig.API)

val.errGroup.Go(func() error {
Expand Down
Loading