From c36a45652ffe833774c84fce6ab4723770bd2da9 Mon Sep 17 00:00:00 2001 From: yinheli Date: Mon, 27 Dec 2021 19:48:35 +0800 Subject: [PATCH] chore: shutdown server with timeout context --- core/xservice/server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/xservice/server.go b/core/xservice/server.go index e4a49e6..fbf1da1 100644 --- a/core/xservice/server.go +++ b/core/xservice/server.go @@ -151,7 +151,9 @@ func (t *serverImpl) Serve() error { t.registerGrpcServiceEtcd() signalx.AddShutdownHook(func(os.Signal) { - _ = server.Shutdown(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + _ = server.Shutdown(ctx) t.grpc.GracefulStop() sentry.Flush(time.Second * 2) log.Info("shutdown", zap.Int("pid", os.Getpid()))