Skip to content

Commit 7ed792b

Browse files
authored
feat: abort health check after 500ms (#17)
1 parent d868b0e commit 7ed792b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/utils/localstack-status.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ function getLocalStackStatus(
8383
}
8484

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

0 commit comments

Comments
 (0)