Skip to content

Commit

Permalink
chore: shutdown server with timeout context
Browse files Browse the repository at this point in the history
  • Loading branch information
yinheli committed Dec 27, 2021
1 parent 7075928 commit c36a456
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/xservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit c36a456

Please sign in to comment.