From baceae107cab31337db370696c6313afb5b61493 Mon Sep 17 00:00:00 2001 From: "Pavel Tumik @ GitPod" <18602811+sagor999@users.noreply.github.com> Date: Thu, 5 May 2022 14:13:48 -0700 Subject: [PATCH] [ws-manager] fix calling dispose multiple times --- components/ws-manager/pkg/manager/annotations.go | 4 ++++ components/ws-manager/pkg/manager/monitor.go | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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