Skip to content

Commit 3b4f236

Browse files
authored
Merge pull request #2440 from JarLob/patch-1
Retry results download if connection times out
2 parents e24377f + 69f9ecc commit 3b4f236

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ import {
7575
writeRepoStates,
7676
} from "./repo-states-store";
7777
import { GITHUB_AUTH_PROVIDER_ID } from "../common/vscode/authentication";
78+
import { FetchError } from "node-fetch";
79+
import { extLogger } from "../common";
80+
81+
const maxRetryCount = 3;
7882

7983
export class VariantAnalysisManager
8084
extends DisposableObject
@@ -613,12 +617,35 @@ export class VariantAnalysisManager
613617
});
614618
}
615619
};
616-
await this.variantAnalysisResultsManager.download(
617-
variantAnalysis.id,
618-
repoTask,
619-
this.getVariantAnalysisStorageLocation(variantAnalysis.id),
620-
updateRepoStateCallback,
621-
);
620+
let retry = 0;
621+
for (;;) {
622+
try {
623+
await this.variantAnalysisResultsManager.download(
624+
variantAnalysis.id,
625+
repoTask,
626+
this.getVariantAnalysisStorageLocation(variantAnalysis.id),
627+
updateRepoStateCallback,
628+
);
629+
break;
630+
} catch (e) {
631+
if (
632+
retry++ < maxRetryCount &&
633+
e instanceof FetchError &&
634+
(e.code === "ETIMEDOUT" || e.code === "ECONNRESET")
635+
) {
636+
void extLogger.log(
637+
`Timeout while trying to download variant analysis with id: ${
638+
variantAnalysis.id
639+
}. Error: ${getErrorMessage(e)}. Retrying...`,
640+
);
641+
continue;
642+
}
643+
void extLogger.log(
644+
`Failed to download variant analysis after ${retry} attempts.`,
645+
);
646+
throw e;
647+
}
648+
}
622649
} catch (e) {
623650
repoState.downloadStatus =
624651
VariantAnalysisScannedRepositoryDownloadStatus.Failed;

extensions/ql-vscode/src/variant-analysis/variant-analysis-results-manager.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { appendFile, pathExists } from "fs-extra";
1+
import { appendFile, pathExists, rm } from "fs-extra";
22
import fetch from "node-fetch";
33
import { EOL } from "os";
44
import { join } from "path";
@@ -82,6 +82,9 @@ export class VariantAnalysisResultsManager extends DisposableObject {
8282

8383
const zipFilePath = join(resultDirectory, "results.zip");
8484

85+
// in case of restarted download delete possible artifact from previous download
86+
await rm(zipFilePath, { force: true });
87+
8588
const response = await fetch(repoTask.artifactUrl);
8689

8790
let responseSize = parseInt(response.headers.get("content-length") || "0");

0 commit comments

Comments
 (0)