Skip to content

Commit 34900f3

Browse files
committed
retry info endpoint a few times
1 parent d40847c commit 34900f3

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/utils/manage.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ async function fetchHealth(): Promise<boolean> {
2626
return false;
2727
}
2828
}
29-
3029
async function fetchLocalStackSessionId(): Promise<string> {
31-
try {
32-
// TODO info endpoint is not available immediately
33-
// potentially improve this later for tracking "vscode:emulator:started"
34-
const infoResponse = await fetch("http://localhost:4566/_localstack/info");
35-
if (infoResponse.ok) {
36-
const info = (await infoResponse.json()) as { session_id?: string };
37-
return info.session_id ?? "";
30+
// retry a few times to allow LocalStack to start up and info become available
31+
for (let attempt = 0; attempt < 5; attempt++) {
32+
try {
33+
const response = await fetch("http://localhost:4566/_localstack/info");
34+
if (response.ok) {
35+
const json = await response.json();
36+
if (typeof json === "object" && json !== null && "session_id" in json) {
37+
return (json as { session_id?: string }).session_id ?? "";
38+
}
39+
return "";
40+
}
41+
} catch {
42+
// ignore error and retry
3843
}
39-
} catch {
40-
// unable to fetch session id
44+
await new Promise((resolve) => setTimeout(resolve, 1000));
4145
}
4246
return "";
4347
}

0 commit comments

Comments
 (0)