diff --git a/components/ws-manager/pkg/manager/annotations.go b/components/ws-manager/pkg/manager/annotations.go index a9ef97cc60e7b2..f5bf12f1361c75 100644 --- a/components/ws-manager/pkg/manager/annotations.go +++ b/components/ws-manager/pkg/manager/annotations.go @@ -66,6 +66,10 @@ const ( // pvcWorkspaceFeatureAnnotation is set on workspaces which are using persistent_volume_claim feature pvcWorkspaceFeatureAnnotation = "gitpod.io/pvcFeature" + // startedDisposalAnnotation sets to true when finalizeWorkspaceContent is called to prevent finalize from + // being called more then once, which can happen due to race between disposalStatusAnnotation update and actOnPodEvent + startedDisposalAnnotation = "gitpod.io/startedDisposal" + // gitpodFinalizerName is the name of the Gitpod finalizer we use to clean up a workspace gitpodFinalizerName = "gitpod.io/finalizer" diff --git a/components/ws-manager/pkg/manager/monitor.go b/components/ws-manager/pkg/manager/monitor.go index ea3e8325bee459..fe9ec8baa43502 100644 --- a/components/ws-manager/pkg/manager/monitor.go +++ b/components/ws-manager/pkg/manager/monitor.go @@ -377,7 +377,7 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt } _, gone := wso.Pod.Annotations[wsk8s.ContainerIsGoneAnnotation] - _, alreadyFinalized := wso.Pod.Annotations[disposalStatusAnnotation] + _, alreadyFinalized := wso.Pod.Annotations[startedDisposalAnnotation] if (terminated || gone) && !alreadyFinalized { // We start finalizing the workspace content only after the container is gone. This way we ensure there's @@ -922,6 +922,11 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb m.finalizerMapLock.Unlock() }() + err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, "true")) + if err != nil { + log.WithError(err).Error("was unable to update pod's start disposal state - this might cause an incorrect disposal state") + } + if doSnapshot { // if this is a prebuild take a snapshot and mark the workspace var res *wsdaemon.TakeSnapshotResponse