Skip to content
Permalink
Browse files
forge: Retry failed fetches a few times
Reviewed-by: ehelin
  • Loading branch information
rwestberg committed Nov 2, 2020
1 parent 7eaebc7 commit d2401270372fbf2ce5126d1113cc0705c6e9139b
Showing 1 changed file with 16 additions and 2 deletions.
@@ -193,12 +193,26 @@ public Repository checkoutAllowStale(HostedRepository hostedRepository, String r
return checkout(hostedRepository, ref, path, true);
}

private void fetchWithRetry(Repository repo, URI url) throws IOException {
IOException lastException = null;
for (int count = 0; count < 10; ++count) {
try {
repo.fetchAll(url, true);
return;
} catch (IOException e) {
lastException = e;
}
}

throw lastException;
}

public Optional<List<String>> lines(HostedRepository hostedRepository, Path p, Hash hash) throws IOException {
var hostedRepositoryInstance = new HostedRepositoryInstance(hostedRepository);
var seedRepo = hostedRepositoryInstance.seedRepository(true);
if (!seedRepo.contains(hash)) {
// It may fail because the seed is stale - need to refresh it now
seedRepo.fetchAll(hostedRepository.url(), true);
fetchWithRetry(seedRepo, hostedRepository.url());
}
return seedRepo.lines(p, hash);
}
@@ -207,7 +221,7 @@ public Repository seedRepository(HostedRepository hostedRepository, boolean allo
var hostedRepositoryInstance = new HostedRepositoryInstance(hostedRepository);
var repo = hostedRepositoryInstance.seedRepository(allowStale);
if (!allowStale) {
repo.fetchAll(hostedRepository.url(), true);
fetchWithRetry(repo, hostedRepository.url());
}
return repo;
}

1 comment on commit d240127

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on d240127 Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.