fix: retry start/restart on network errors
When Docker starts a container, it creates network interfaces which triggers Chrome's ERR_NETWORK_CHANGED error, aborting the request. The backend successfully starts the container but the frontend never gets the response, showing 'failed to create session' even though the session is up. Fix: Add retry with exponential backoff for startInstance and restartInstance when network errors occur (no HTTP response). Retries up to 2 times with 1.5s delay between attempts. Fixes: False 'failed to create session' errors when launching tools.
This commit is contained in:
@@ -71,13 +71,23 @@ export async function startInstance(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
instanceId: string,
|
||||
configProfileId?: string
|
||||
configProfileId?: string,
|
||||
retries = 2
|
||||
): Promise<{ status: string; url?: string }> {
|
||||
const response = await apiClient.post(
|
||||
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/start`,
|
||||
{ config_profile_id: configProfileId }
|
||||
);
|
||||
return response.data;
|
||||
try {
|
||||
const response = await apiClient.post(
|
||||
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/start`,
|
||||
{ config_profile_id: configProfileId }
|
||||
);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
// Retry on network errors (e.g. Docker creating network interfaces)
|
||||
if (retries > 0 && !error.response) {
|
||||
await new Promise((r) => setTimeout(r, 1500));
|
||||
return startInstance(projectId, repoId, instanceId, configProfileId, retries - 1);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function stopInstance(
|
||||
@@ -95,13 +105,23 @@ export async function restartInstance(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
instanceId: string,
|
||||
configProfileId?: string
|
||||
configProfileId?: string,
|
||||
retries = 2
|
||||
): Promise<{ status: string; url?: string }> {
|
||||
const response = await apiClient.post(
|
||||
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/restart`,
|
||||
{ config_profile_id: configProfileId }
|
||||
);
|
||||
return response.data;
|
||||
try {
|
||||
const response = await apiClient.post(
|
||||
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/restart`,
|
||||
{ config_profile_id: configProfileId }
|
||||
);
|
||||
return response.data;
|
||||
} catch (error: any) {
|
||||
// Retry on network errors (e.g. Docker creating network interfaces)
|
||||
if (retries > 0 && !error.response) {
|
||||
await new Promise((r) => setTimeout(r, 1500));
|
||||
return restartInstance(projectId, repoId, instanceId, configProfileId, retries - 1);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteInstance(
|
||||
|
||||
Reference in New Issue
Block a user