Skip to content

Commit

Permalink
fix: handle panics in Omni and Talos UI watches
Browse files Browse the repository at this point in the history
Safety net against any bugs there.

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Jun 13, 2024
1 parent 6286340 commit 4ecb175
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion internal/backend/runtime/omni/omni.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,19 @@ func (r *Runtime) Run(ctx context.Context, eg newgroup.EGroup) {
}

// Watch implements runtime.Runtime.
func (r *Runtime) Watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) error {
func (r *Runtime) Watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) (err error) {
defer func() {
if p := recover(); p != nil {
err = fmt.Errorf("watch panic")

r.logger.Error("watch panicked", zap.Stack("stack"), zap.Error(err))
}
}()

return r.watch(ctx, events, setters...)
}

func (r *Runtime) watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) error {
opts := runtime.NewQueryOptions(setters...)

var (
Expand Down
14 changes: 13 additions & 1 deletion internal/backend/runtime/talos/talos.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ func New(clientFactory *ClientFactory, logger *zap.Logger) *Runtime {
}

// Watch implements runtime.Runtime.
func (r *Runtime) Watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) error {
func (r *Runtime) Watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) (err error) {
defer func() {
if p := recover(); p != nil {
err = fmt.Errorf("watch panic")

r.logger.Error("watch panicked", zap.Stack("stack"), zap.Error(err))
}
}()

return r.watch(ctx, events, setters...)
}

func (r *Runtime) watch(ctx context.Context, events chan<- runtime.WatchResponse, setters ...runtime.QueryOption) error {
opts := runtime.NewQueryOptions(setters...)

switch len(opts.Nodes) {
Expand Down

0 comments on commit 4ecb175

Please sign in to comment.