Skip to content

Commit 247e69d

Browse files
Merge master into feature/model-selection
2 parents 9477737 + 9c0ad28 commit 247e69d

File tree

1 file changed

+9
-1
lines changed
  • packages/core/src/awsService/sagemaker/detached-server

1 file changed

+9
-1
lines changed

packages/core/src/awsService/sagemaker/detached-server/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import os from 'os'
1313
import { join } from 'path'
1414
import { SpaceMappings } from '../types'
1515
import open from 'open'
16+
import { ConfiguredRetryStrategy } from '@smithy/util-retry'
1617
export { open }
1718

1819
export const mappingFilePath = join(os.homedir(), '.aws', '.sagemaker-space-profiles')
@@ -22,6 +23,13 @@ const tempFilePath = `${mappingFilePath}.tmp`
2223
let isWriting = false
2324
const writeQueue: Array<() => Promise<void>> = []
2425

26+
// Currently SSM registration happens asynchronously with App launch, which can lead to
27+
// StartSession Internal Failure when connecting to a fresly-started Space.
28+
// To mitigate, spread out retries over multiple seconds instead of sending all retries within a second.
29+
// Backoff sequence: 1500ms, 2250ms, 3375ms
30+
// Retry timing: 1500ms, 3750ms, 7125ms
31+
const startSessionRetryStrategy = new ConfiguredRetryStrategy(3, (attempt: number) => 1000 * 1.5 ** attempt)
32+
2533
/**
2634
* Reads the local endpoint info file (default or via env) and returns pid & port.
2735
* @throws Error if the file is missing, invalid JSON, or missing fields
@@ -83,7 +91,7 @@ export function parseArn(arn: string): { region: string; accountId: string; spac
8391

8492
export async function startSagemakerSession({ region, connectionIdentifier, credentials }: any) {
8593
const endpoint = process.env.SAGEMAKER_ENDPOINT || `https://sagemaker.${region}.amazonaws.com`
86-
const client = new SageMakerClient({ region, credentials, endpoint })
94+
const client = new SageMakerClient({ region, credentials, endpoint, retryStrategy: startSessionRetryStrategy })
8795
const command = new StartSessionCommand({ ResourceIdentifier: connectionIdentifier })
8896
return client.send(command)
8997
}

0 commit comments

Comments
 (0)