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

Merged
merged 4 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
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
Loading