Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding retry strategy in KurtosisUpgrader #2464

Merged
merged 2 commits into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Alert, AlertDescription, AlertIcon, Box, Button, Flex } from "@chakra-ui/react";
import { PropsWithChildren, useEffect, useState } from "react";
import { GetCloudInstanceConfigResponse } from "enclave-manager-sdk/build/kurtosis_backend_server_api_pb";
import { PropsWithChildren, useCallback, useEffect, useState } from "react";
import { FiDownloadCloud, FiRotateCcw } from "react-icons/fi";
import { GoBug } from "react-icons/go";
import { useKurtosisClient } from "../../../client/enclaveManager/KurtosisClientContext";
Expand Down Expand Up @@ -58,6 +59,31 @@ export const KurtosisUpgrader = () => {
}
};

const wait = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

const getCloudInstanceConfigWithRetry = useCallback(
async (tries: number, interval: number): Promise<GetCloudInstanceConfigResponse> => {
let getCloudInstanceConfigResponse: GetCloudInstanceConfigResponse = new GetCloudInstanceConfigResponse();
try {
getCloudInstanceConfigResponse = await kurtosisClient.getCloudInstanceConfig(skipCache);
} catch (e) {
const newTries = tries - 1;

if (newTries === 0) {
throw e;
}

await wait(interval);

return getCloudInstanceConfigWithRetry(newTries, interval);
}
return getCloudInstanceConfigResponse;
},
[kurtosisClient],
);

// Check once on load if a new Kurtosis version is available
useEffect(() => {
if (!kurtosisClient.isRunningInCloud()) return;
Expand All @@ -74,7 +100,8 @@ export const KurtosisUpgrader = () => {

const interval = setInterval(async () => {
try {
const getCloudInstanceConfigResponse = await kurtosisClient.getCloudInstanceConfig(skipCache);
// Calling it with retries because when the engine is restarted it won't return a response for a few seconds
const getCloudInstanceConfigResponse = await getCloudInstanceConfigWithRetry(5, 2000);
const instanceStatus = getCloudInstanceConfigResponse.status;
if (instanceStatus === "running") {
setUpgradeStatus(UpgradeStatus.SUCCESS);
Expand All @@ -88,7 +115,7 @@ export const KurtosisUpgrader = () => {
}, 10000);

return () => clearInterval(interval);
}, [upgradeStatus, kurtosisClient]);
}, [upgradeStatus, kurtosisClient, getCloudInstanceConfigWithRetry]);

if (upgradeStatus === UpgradeStatus.NONE) {
return null;
Expand Down
Loading