Skip to content

Commit

Permalink
fix nil pointer panic for monitor
Browse files Browse the repository at this point in the history
Signed-off-by: Ye Sijun <[email protected]>
  • Loading branch information
junnplus authored and Kirtana Ashok committed Jan 18, 2023
1 parent 8b77c35 commit c7a8599
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions runtime/restart/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,30 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) {
}
var changes []change
for _, c := range containers {
var (
task containerd.Task
status containerd.Status
err error
)
labels, err := c.Labels(ctx)
if err != nil {
return nil, err
}
desiredStatus := containerd.ProcessStatus(labels[restart.StatusLabel])
task, err := c.Task(ctx, nil)
if err != nil && desiredStatus == containerd.Stopped {
continue
}
status, err := task.Status(ctx)
if err != nil && desiredStatus == containerd.Stopped {
continue
if task, err = c.Task(ctx, nil); err == nil {
if status, err = task.Status(ctx); err == nil {
if desiredStatus == status.Status {
continue
}
}
}
if desiredStatus == status.Status {
continue

// Task or Status return error, only desired to stop
if err != nil {
logrus.WithError(err).Error("monitor")
if desiredStatus != containerd.Stopped {
continue
}
}

switch desiredStatus {
Expand Down

0 comments on commit c7a8599

Please sign in to comment.