Skip to content

Commit

Permalink
Avoid panics when stopping a not-quite-started debug manager (#6020)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandealwis authored Jun 15, 2021
1 parent f76873c commit fe08298
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/skaffold/kubernetes/debugging/container_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ func NewContainerManager(podSelector kubernetes.PodSelector) *ContainerManager {
// Create the channel here as Stop() may be called before Start() when a build fails, thus
// avoiding the possibility of closing a nil channel. Channels are cheap.
return &ContainerManager{
podWatcher: kubernetes.NewPodWatcher(podSelector),
active: map[string]string{},
events: make(chan kubernetes.PodEvent),
podWatcher: kubernetes.NewPodWatcher(podSelector),
active: map[string]string{},
events: make(chan kubernetes.PodEvent),
stopWatcher: func() {},
}
}

Expand All @@ -65,6 +66,8 @@ func (d *ContainerManager) Start(ctx context.Context, namespaces []string) error
d.stopWatcher = stopWatcher

go func() {
defer stopWatcher()

for {
select {
case <-ctx.Done():
Expand All @@ -84,9 +87,10 @@ func (d *ContainerManager) Start(ctx context.Context, namespaces []string) error

func (d *ContainerManager) Stop() {
// if nil then debug mode probably not enabled
if d != nil {
d.stopWatcher()
if d == nil {
return
}
d.stopWatcher()
}

func (d *ContainerManager) Name() string {
Expand Down

0 comments on commit fe08298

Please sign in to comment.