When the server exits (^C or because docker/systemd exits it), streaming gRPC clients must be
closed. Currently, the server does not exit until the gRPC client disconnects.
This commit is contained in:
@@ -17,12 +17,15 @@ import (
|
||||
// Server implements the MaglevServer gRPC interface.
|
||||
type Server struct {
|
||||
UnimplementedMaglevServer
|
||||
ctx context.Context
|
||||
checker *checker.Checker
|
||||
}
|
||||
|
||||
// NewServer creates a Server backed by the given Checker.
|
||||
func NewServer(c *checker.Checker) *Server {
|
||||
return &Server{checker: c}
|
||||
// NewServer creates a Server backed by the given Checker. The provided context
|
||||
// controls the lifetime of streaming RPCs: cancelling it closes all active
|
||||
// WatchBackendEvents streams so that grpc.Server.GracefulStop can complete.
|
||||
func NewServer(ctx context.Context, c *checker.Checker) *Server {
|
||||
return &Server{ctx: ctx, checker: c}
|
||||
}
|
||||
|
||||
// ListFrontends returns the names of all configured frontends.
|
||||
@@ -112,6 +115,8 @@ func (s *Server) WatchBackendEvents(_ *WatchRequest, stream Maglev_WatchBackendE
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-s.ctx.Done():
|
||||
return status.Error(codes.Unavailable, "server shutting down")
|
||||
case <-stream.Context().Done():
|
||||
return nil
|
||||
case e, ok := <-ch:
|
||||
|
||||
Reference in New Issue
Block a user