Skip to content

Commit 773f62d

Browse files
committed
fix(smus): Improve error handling when the Space takes too long to start
1 parent e1abbe6 commit 773f62d

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

packages/core/src/awsService/sagemaker/commands.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ async function handleRunningSpaceWithDisabledAccess(
332332
await client.waitForAppInService(
333333
node.spaceApp.DomainId!,
334334
spaceName,
335-
node.spaceApp.SpaceSettingsSummary!.AppType!
335+
node.spaceApp.SpaceSettingsSummary!.AppType!,
336+
progress
336337
)
337338
await tryRemoteConnection(node, ctx, progress)
338339
} catch (err: any) {
@@ -376,7 +377,8 @@ async function handleStoppedSpace(
376377
await client.waitForAppInService(
377378
node.spaceApp.DomainId!,
378379
spaceName,
379-
node.spaceApp.SpaceSettingsSummary!.AppType!
380+
node.spaceApp.SpaceSettingsSummary!.AppType!,
381+
progress
380382
)
381383
await tryRemoteConnection(node, ctx, progress)
382384
}

packages/core/src/shared/clients/sagemaker.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/*!
2-
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
1+
/*! * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
32
* SPDX-License-Identifier: Apache-2.0
43
*/
54

@@ -59,6 +58,12 @@ const appTypeSettingsMap: Record<string, string> = {
5958
[AppType.CodeEditor as string]: 'CodeEditorAppSettings',
6059
} as const
6160

61+
export const waitForAppConfig = {
62+
softTimeoutRetries: 12,
63+
hardTimeoutRetries: 120,
64+
intervalMs: 5000,
65+
}
66+
6267
export interface SagemakerSpaceApp extends SpaceDetails {
6368
App?: AppDetails
6469
DomainSpaceKey: string
@@ -364,10 +369,9 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
364369
domainId: string,
365370
spaceName: string,
366371
appType: string,
367-
maxRetries = 30,
368-
intervalMs = 5000
372+
progress?: vscode.Progress<{ message?: string; increment?: number }>
369373
): Promise<void> {
370-
for (let attempt = 0; attempt < maxRetries; attempt++) {
374+
for (let attempt = 0; attempt < waitForAppConfig.hardTimeoutRetries; attempt++) {
371375
const { Status } = await this.describeApp({
372376
DomainId: domainId,
373377
SpaceName: spaceName,
@@ -383,7 +387,13 @@ export class SagemakerClient extends ClientWrapper<SageMakerClient> {
383387
throw new ToolkitError(`App failed to start. Status: ${Status}`)
384388
}
385389

386-
await sleep(intervalMs)
390+
if (attempt === waitForAppConfig.softTimeoutRetries) {
391+
progress?.report({
392+
message: `Starting the space is taking longer than usual. The space will connect when ready`,
393+
})
394+
}
395+
396+
await sleep(waitForAppConfig.intervalMs)
387397
}
388398

389399
throw new ToolkitError(`Timed out waiting for app "${spaceName}" to reach "InService" status.`)

packages/core/src/test/shared/clients/sagemakerClient.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,18 @@ describe('SagemakerClient.waitForAppInService', function () {
251251
it('times out after max retries', async function () {
252252
describeAppStub.resolves({ Status: 'Pending' })
253253

254-
await assert.rejects(
255-
client.waitForAppInService('domain1', 'space1', 'CodeEditor', 2, 10),
256-
/Timed out waiting for app/
257-
)
254+
const sagemakerModule = await import('../../../shared/clients/sagemaker.js')
255+
const originalValue = sagemakerModule.waitForAppConfig.hardTimeoutRetries
256+
sagemakerModule.waitForAppConfig.hardTimeoutRetries = 3
257+
258+
try {
259+
await assert.rejects(
260+
client.waitForAppInService('domain1', 'space1', 'CodeEditor'),
261+
/Timed out waiting for app/
262+
)
263+
} finally {
264+
sagemakerModule.waitForAppConfig.hardTimeoutRetries = originalValue
265+
}
258266
})
259267
})
260268

0 commit comments

Comments
 (0)