refactor: add timeout to server closing

main
sundowndev 2024-02-28 16:18:25 +04:00
parent 5a8da7ce9e
commit e854597382
1 changed files with 2 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
"google.golang.org/grpc/health" "google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1" "google.golang.org/grpc/health/grpc_health_v1"
"net" "net"
"time"
) )
type Server struct { type Server struct {
@ -49,6 +50,7 @@ func (s *Server) Listen(addr string) error {
func (s *Server) Close() error { func (s *Server) Close() error {
s.healthSrv.Shutdown() s.healthSrv.Shutdown()
time.Sleep(5 * time.Second) // Set a timeout in which all services will be marked as unhealthy
s.grpcSrv.GracefulStop() s.grpcSrv.GracefulStop()