Skip to content

Commit cc893be

Browse files
sagor999roboquat
authored andcommitted
[ws-manager] fix calling dispose multiple times
1 parent d90e6ab commit cc893be

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

components/ws-manager/pkg/manager/annotations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ const (
6666
// pvcWorkspaceFeatureAnnotation is set on workspaces which are using persistent_volume_claim feature
6767
pvcWorkspaceFeatureAnnotation = "gitpod.io/pvcFeature"
6868

69+
// startedDisposalAnnotation sets to true when finalizeWorkspaceContent is called to prevent finalize from
70+
// being called more then once, which can happen due to race between disposalStatusAnnotation update and actOnPodEvent
71+
startedDisposalAnnotation = "gitpod.io/startedDisposal"
72+
6973
// gitpodFinalizerName is the name of the Gitpod finalizer we use to clean up a workspace
7074
gitpodFinalizerName = "gitpod.io/finalizer"
7175

components/ws-manager/pkg/manager/monitor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func actOnPodEvent(ctx context.Context, m actingManager, status *api.WorkspaceSt
377377
}
378378

379379
_, gone := wso.Pod.Annotations[wsk8s.ContainerIsGoneAnnotation]
380-
_, alreadyFinalized := wso.Pod.Annotations[disposalStatusAnnotation]
380+
_, alreadyFinalized := wso.Pod.Annotations[startedDisposalAnnotation]
381381

382382
if (terminated || gone) && !alreadyFinalized {
383383
// 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
922922
m.finalizerMapLock.Unlock()
923923
}()
924924

925+
err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, "true"))
926+
if err != nil {
927+
log.WithError(err).Error("was unable to update pod's start disposal state - this might cause an incorrect disposal state")
928+
}
929+
925930
if doSnapshot {
926931
// if this is a prebuild take a snapshot and mark the workspace
927932
var res *wsdaemon.TakeSnapshotResponse

0 commit comments

Comments
 (0)