fix: add grpc server graceful shutdown

This commit is contained in:
Mustafa Sencer Özcan
2026-01-14 18:36:40 +01:00
parent 9f44f868aa
commit 87e65fcac5
+15 -2
View File
@@ -168,8 +168,21 @@ func (s *gPRCServerService) Run(ctx context.Context) error {
return err
case <-ctx.Done():
}
s.logger.Warn("GRPC server: shutting down")
s.server.Stop()
s.logger.Warn("GRPC server: initiating graceful shutdown")
gracefulStopDone := make(chan struct{})
go func() {
s.server.GracefulStop()
close(gracefulStopDone)
}()
select {
case <-gracefulStopDone:
s.logger.Info("GRPC server: graceful shutdown complete")
case <-time.After(30 * time.Second):
s.logger.Warn("GRPC server: graceful shutdown timed out, forcing stop")
s.server.Stop()
}
return ctx.Err()
}