Skip to content

Commit b89a417

Browse files
utam0kroboquat
authored andcommitted
ws-manager: Fix consistency of disposed ws between ws-daemon and ws-manager
1 parent e75f602 commit b89a417

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,18 +1090,6 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
10901090
return true, nil, status.Errorf(codes.Unavailable, "cannot connect to workspace daemon: %q", err)
10911091
}
10921092

1093-
// only build prebuild snapshots of initialized/ready workspaces.
1094-
if tpe == api.WorkspaceType_PREBUILD {
1095-
_, err = snc.WaitForInit(ctx, &wsdaemon.WaitForInitRequest{Id: workspaceID})
1096-
if st, ok := grpc_status.FromError(err); ok && st.Code() == codes.FailedPrecondition &&
1097-
(st.Message() == "workspace is not initializing or ready" || st.Message() == "workspace is not ready") {
1098-
log.Warn("skipping snapshot creation because content-initializer never finished or the workspace reached a ready state")
1099-
doSnapshot = false
1100-
}
1101-
}
1102-
1103-
ctx, cancelReq := context.WithTimeout(ctx, time.Duration(m.manager.Config.Timeouts.ContentFinalization))
1104-
m.finalizerMap.Store(workspaceID, cancelReq)
11051093
defer func() {
11061094
// we're done disposing - remove from the finalizerMap
11071095
val, ok := m.finalizerMap.LoadAndDelete(workspaceID)
@@ -1113,6 +1101,26 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
11131101
cancelReq()
11141102
}()
11151103

1104+
// only build prebuild snapshots of initialized/ready workspaces.
1105+
if tpe == api.WorkspaceType_PREBUILD {
1106+
_, err = snc.WaitForInit(ctx, &wsdaemon.WaitForInitRequest{Id: workspaceID})
1107+
if st, ok := grpc_status.FromError(err); ok {
1108+
if st.Code() == codes.FailedPrecondition &&
1109+
(st.Message() == "workspace is not initializing or ready" || st.Message() == "workspace is not ready") {
1110+
log.Warn("skipping snapshot creation because content-initializer never finished or the workspace reached a ready state")
1111+
doSnapshot = false
1112+
} else if st.Code() == codes.NotFound {
1113+
// the workspace has gone some reason
1114+
// e.g. since it was a retry, it already succeeded the first time.
1115+
log.WithError(err).Warnf("skipping snapshot and disposing because the workspace has already gone")
1116+
return false, &csapi.GitStatus{}, nil
1117+
}
1118+
}
1119+
}
1120+
1121+
ctx, cancelReq := context.WithTimeout(ctx, time.Duration(m.manager.Config.Timeouts.ContentFinalization))
1122+
m.finalizerMap.Store(workspaceID, cancelReq)
1123+
11161124
err = m.manager.markWorkspace(ctx, workspaceID, addMark(startedDisposalAnnotation, util.BooleanTrueString))
11171125
if err != nil {
11181126
tracing.LogError(span, err)

0 commit comments

Comments
 (0)