Skip to content

Commit 97a61b7

Browse files
committed
[WorkspaceStarter] Fail instance on image resolution errors
1 parent 952d922 commit 97a61b7

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

components/server/src/workspace/workspace-starter.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -368,31 +368,13 @@ export class WorkspaceStarter {
368368
workspace.context,
369369
);
370370

371-
const forceRebuild = !!workspace.context.forceImageBuild;
372-
try {
373-
// if we need to build the workspace image we must not wait for actuallyStartWorkspace to return as that would block the
374-
// frontend until the image is built.
375-
const additionalAuth = await this.getAdditionalImageAuth(envVars);
376-
const needsImageBuild =
377-
forceRebuild || (await this.needsImageBuild(ctx, user, workspace, instance, additionalAuth));
378-
if (needsImageBuild) {
379-
instance.status.conditions = {
380-
neededImageBuild: true,
381-
};
382-
}
383-
ctx.span?.setTag("needsImageBuild", needsImageBuild);
384-
} catch (err) {
385-
// if we fail to check if the workspace needs an image build (e.g. becuase the image builder is unavailable),
386-
// we must properly fail the workspace instance, i.e. set its status to stopped, deal with prebuilds etc.
387-
//
388-
// Once we've reached actuallyStartWorkspace that function will take care of failing the instance.
389-
await this.failInstanceStart(ctx, err, workspace, instance, abortSignal);
390-
throw err;
391-
}
392-
393-
await this.actuallyStartWorkspace(ctx, instance, workspace, user, envVars, abortSignal, forceRebuild);
371+
await this.actuallyStartWorkspace(ctx, instance, workspace, user, envVars, abortSignal);
394372
} catch (err) {
395-
log.error({ instanceId }, "error in reconcileWorkspaceStart", err);
373+
this.logAndTraceStartWorkspaceError(
374+
ctx,
375+
{ userId: user.id, workspaceId: workspace.id, instanceId },
376+
err,
377+
);
396378
} finally {
397379
ctx.span.finish();
398380
}
@@ -532,7 +514,6 @@ export class WorkspaceStarter {
532514
user: User,
533515
envVars: ResolvedEnvVars,
534516
abortSignal: RedlockAbortSignal,
535-
forceRebuild?: boolean,
536517
): Promise<void> {
537518
const span = TraceContext.startSpan("actuallyStartWorkspace", ctx);
538519
const region = instance.configuration.regionPreference;
@@ -543,6 +524,7 @@ export class WorkspaceStarter {
543524
organizationId: workspace.organizationId,
544525
workspaceId: workspace.id,
545526
};
527+
const forceRebuild = !!workspace.context.forceImageBuild;
546528
log.info(logCtx, "Attempting to start workspace", {
547529
forceRebuild: forceRebuild,
548530
});
@@ -1216,6 +1198,18 @@ export class WorkspaceStarter {
12161198
const span = TraceContext.startSpan("buildWorkspaceImage", ctx);
12171199

12181200
try {
1201+
// TODO(gpl) I looks like we really don't need the whole "needsImageBuild" anymore:
1202+
// Before we used it to distinguish between sync/async, now we are always async.
1203+
// Still keeping it here for now to understand whether there are any side effects in image-builder-mk3
1204+
const needsImageBuild =
1205+
forceRebuild || (await this.needsImageBuild(ctx, user, workspace, instance, additionalAuth));
1206+
if (needsImageBuild) {
1207+
instance.status.conditions = {
1208+
neededImageBuild: true,
1209+
};
1210+
}
1211+
ctx.span?.setTag("needsImageBuild", needsImageBuild);
1212+
12191213
// Start build...
12201214
const client = await this.getImageBuilderClient(user, workspace, instance, region);
12211215
const { src, auth, disposable } = await this.prepareBuildRequest(
@@ -1352,7 +1346,11 @@ export class WorkspaceStarter {
13521346
await this.failInstanceStart({ span }, err, workspace, instance, abortSignal);
13531347

13541348
const looksLikeUserError = (msg: string): boolean => {
1355-
return msg.startsWith("build failed:") || msg.includes("headless task failed:");
1349+
return (
1350+
msg.startsWith("build failed:") ||
1351+
msg.includes("headless task failed:") ||
1352+
msg.includes("cannot resolve image")
1353+
);
13561354
};
13571355
if (looksLikeUserError(message)) {
13581356
log.info(

0 commit comments

Comments
 (0)