From d9727fc03d52dca1e3c13f38f20940fd789c2746 Mon Sep 17 00:00:00 2001 From: h0n9 Date: Thu, 3 Aug 2023 11:31:26 -0700 Subject: [PATCH 1/2] Gracefully shutdown lake service as well --- cli/agent/agent.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/agent/agent.go b/cli/agent/agent.go index 9c0ef23..2d878dc 100644 --- a/cli/agent/agent.go +++ b/cli/agent/agent.go @@ -52,7 +52,10 @@ var Cmd = &cobra.Command{ ctx, cancel := context.WithCancel(context.Background()) logger.Info().Msg("initalized context") - var grpcServer *grpc.Server = nil + var ( + lakeService *lake.Service = nil + grpcServer *grpc.Server = nil + ) sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) @@ -65,13 +68,16 @@ var Cmd = &cobra.Command{ if grpcServer != nil { grpcServer.GracefulStop() } + if lakeService != nil { + lakeService.Close() + } wg.Done() }() logger.Info().Msg("listening os signal: SIGINT, SIGTERM") grpcServer = grpc.NewServer() logger.Info().Msg("initalized gRPC server") - lakeService, err := lake.NewService( + lakeService, err = lake.NewService( ctx, &logger, []byte(seed), From 5508dfc79f2b632032ee78ea7d55bf38fbad1bc1 Mon Sep 17 00:00:00 2001 From: h0n9 Date: Thu, 3 Aug 2023 11:33:26 -0700 Subject: [PATCH 2/2] Enhance logging --- cli/agent/agent.go | 2 ++ lake/lake.go | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/agent/agent.go b/cli/agent/agent.go index 2d878dc..cfbd83a 100644 --- a/cli/agent/agent.go +++ b/cli/agent/agent.go @@ -67,9 +67,11 @@ var Cmd = &cobra.Command{ cancel() if grpcServer != nil { grpcServer.GracefulStop() + logger.Info().Msg("gracefully stopped gRPC server") } if lakeService != nil { lakeService.Close() + logger.Info().Msg("closed lake service") } wg.Done() }() diff --git a/lake/lake.go b/lake/lake.go index a1e14fa..e7ff46f 100644 --- a/lake/lake.go +++ b/lake/lake.go @@ -47,7 +47,6 @@ func (service *Service) Close() { if service.relayer != nil { service.relayer.Close() } - service.logger.Info().Msg("closed lake service") } func (service *Service) Publish(ctx context.Context, req *pb.PublishReq) (*pb.PublishRes, error) {