diff --git a/components/ws-daemon/pkg/dispatch/dispatch.go b/components/ws-daemon/pkg/dispatch/dispatch.go index a0891c35eeb181..5d791c498e926c 100644 --- a/components/ws-daemon/pkg/dispatch/dispatch.go +++ b/components/ws-daemon/pkg/dispatch/dispatch.go @@ -148,9 +148,12 @@ func (d *Dispatch) Close() error { defer d.mu.Unlock() close(d.stopchan) - for _, c := range d.ctxs { - c.Cancel() + for _, state := range d.ctxs { + if state != nil && state.Cancel != nil { + state.Cancel() + } } + d.ctxs = make(map[string]*workspaceState) return nil @@ -231,7 +234,11 @@ func (d *Dispatch) handlePodUpdate(oldPod, newPod *corev1.Pod) { go func() { // no matter if the container was deleted or not - we've lost our guard that was waiting for that to happen. // Hence, we must stop listening for it to come into existence and cancel the context. - d.Runtime.WaitForContainerStop(waitForPodCtx, workspaceInstanceID) + err := d.Runtime.WaitForContainerStop(waitForPodCtx, workspaceInstanceID) + if err != nil { + log.WithError(err).WithFields(owi).Error("unexpected waiting for container to stop") + } + cancel() }()