@@ -1090,18 +1090,6 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1090
1090
return true , nil , status .Errorf (codes .Unavailable , "cannot connect to workspace daemon: %q" , err )
1091
1091
}
1092
1092
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 )
1105
1093
defer func () {
1106
1094
// we're done disposing - remove from the finalizerMap
1107
1095
val , ok := m .finalizerMap .LoadAndDelete (workspaceID )
@@ -1113,6 +1101,26 @@ func (m *Monitor) finalizeWorkspaceContent(ctx context.Context, wso *workspaceOb
1113
1101
cancelReq ()
1114
1102
}()
1115
1103
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
+
1116
1124
err = m .manager .markWorkspace (ctx , workspaceID , addMark (startedDisposalAnnotation , util .BooleanTrueString ))
1117
1125
if err != nil {
1118
1126
tracing .LogError (span , err )
0 commit comments