From bed4ba3ac83413c63c002fcd1d5e72f6199c4bc1 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 29 Sep 2022 23:33:28 +0800 Subject: [PATCH] fix: add close for grpcOnly mode (#13418) --- CHANGELOG.md | 1 + server/start.go | 18 +++++++----------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8b5ca65b4d4..7de6291c85d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -174,6 +174,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (Store) [#13334](https://github.com/cosmos/cosmos-sdk/pull/13334) Call streaming listeners for deliver tx event, it was removed accidentally. * (grpc) [#13352](https://github.com/cosmos/cosmos-sdk/pull/13352) fix grpc query panic that could crash the node. * (snapshot) [#13400](https://github.com/cosmos/cosmos-sdk/pull/13400) Fix snapshot checksum issue in golang 1.19. +* (grpc) [#13418](https://github.com/cosmos/cosmos-sdk/pull/13418) Add close for grpc only mode. ### Deprecated diff --git a/server/start.go b/server/start.go index beb51729b686..1cee1089d130 100644 --- a/server/start.go +++ b/server/start.go @@ -417,13 +417,18 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App if err != nil { return err } - + defer grpcSrv.Stop() if config.GRPCWeb.Enable { grpcWebSrv, err = servergrpc.StartGRPCWeb(grpcSrv, config) if err != nil { ctx.Logger.Error("failed to start grpc-web http server: ", err) return err } + defer func() { + if err := grpcWebSrv.Close(); err != nil { + ctx.Logger.Error("failed to close grpc-web http server: ", err) + } + }() } } @@ -486,7 +491,7 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App } defer func() { - if tmNode.IsRunning() { + if tmNode != nil && tmNode.IsRunning() { _ = tmNode.Stop() } @@ -498,15 +503,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App _ = apiSrv.Close() } - if grpcSrv != nil { - grpcSrv.Stop() - if grpcWebSrv != nil { - if err := grpcWebSrv.Close(); err != nil { - ctx.Logger.Error("failed to close grpc-web http server: ", err) - } - } - } - ctx.Logger.Info("exiting...") }()