Skip to content

Commit

Permalink
fix: add signal handling to SyncFlags grpc (open-feature#1176)
Browse files Browse the repository at this point in the history
Signed-off-by: Giovanni Liva <[email protected]>
  • Loading branch information
thisthat authored Jan 30, 2024
1 parent 184d3e0 commit 5c8ed7c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions core/pkg/service/sync/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type handler struct {
syncv1grpc.UnimplementedFlagSyncServiceServer
syncStore subscriptions.Manager
logger *logger.Logger
// ctx is used to handle SIG[INT|TERM]
ctx context.Context
}

func (nh *handler) SyncFlags(
Expand All @@ -40,6 +42,8 @@ func (nh *handler) SyncFlags(
}
case <-server.Context().Done():
return nil
case <-nh.ctx.Done():
return nil
}
}
}
Expand All @@ -64,6 +68,8 @@ type oldHandler struct {
rpc.UnimplementedFlagSyncServiceServer
syncStore subscriptions.Manager
logger *logger.Logger
// ctx is used to handle SIG[INT|TERM]
ctx context.Context
}

func (l *oldHandler) FetchAllFlags(ctx context.Context, req *syncv1.FetchAllFlagsRequest) (
Expand Down Expand Up @@ -102,6 +108,8 @@ func (l *oldHandler) SyncFlags(
}
case <-stream.Context().Done():
return nil
case <-l.ctx.Done():
return nil
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/pkg/service/sync/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ type Server struct {
metricServerReady bool
}

func NewServer(logger *logger.Logger, store subscriptions.Manager) *Server {
func NewServer(ctx context.Context, logger *logger.Logger, store subscriptions.Manager) *Server {
theOldHandler := &oldHandler{
logger: logger,
syncStore: store,
ctx: ctx,
}
theNewHandler := &handler{
logger: logger,
syncStore: store,
ctx: ctx,
}
return &Server{
oldHandler: theOldHandler,
Expand Down
2 changes: 1 addition & 1 deletion flagd-proxy/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var startCmd = &cobra.Command{
ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)

syncStore := subscriptions.NewManager(ctx, logger)
s := syncServer.NewServer(logger, syncStore)
s := syncServer.NewServer(ctx, logger, syncStore)

cfg := service.Configuration{
ReadinessProbe: func() bool { return true },
Expand Down

0 comments on commit 5c8ed7c

Please sign in to comment.