Skip to content

Commit 30a5a71

Browse files
committed
feat: abort health check after 500ms
1 parent 56e59d9 commit 30a5a71

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/utils/localstack-status.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,20 @@ function getLocalStackStatus(
8181
}
8282
}
8383

84-
async function fetchHealth(): Promise<boolean> {
85-
// health is ok in the majority of use cases, however, determining status based on it can be flaky.
86-
// for example, if localstack becomes unhealthy while running for reasons other that stop then reporting "stopping" may be misleading.
87-
// though we don't know if it happens often.
84+
async function fetchHealth(outputChannel: LogOutputChannel): Promise<boolean> {
85+
// Abort the fetch if it takes more than 500ms.
86+
const controller = new AbortController();
87+
setTimeout(() => controller.abort(), 500);
88+
8889
try {
89-
const response = await fetch("http://localhost:4566/_localstack/health");
90+
// health is ok in the majority of use cases, however, determining status based on it can be flaky.
91+
// for example, if localstack becomes unhealthy while running for reasons other that stop then reporting "stopping" may be misleading.
92+
// though we don't know if it happens often.
93+
const response = await fetch("http://localhost:4566/_localstack/health", {
94+
signal: controller.signal,
95+
});
9096
return response.ok;
91-
} catch {
97+
} catch (err) {
9298
return false;
9399
}
94100
}

0 commit comments

Comments
 (0)