修复缓存异常时 FetchTask 无限循环的问题 (#4844)
This commit is contained in:
@@ -112,7 +112,7 @@ public final class UpdateChecker {
|
|||||||
try {
|
try {
|
||||||
result = checkUpdate(channel, preview);
|
result = checkUpdate(channel, preview);
|
||||||
LOG.info("Latest version (" + channel + ", preview=" + preview + ") is " + result);
|
LOG.info("Latest version (" + channel + ", preview=" + preview + ") is " + result);
|
||||||
} catch (IOException e) {
|
} catch (Throwable e) {
|
||||||
LOG.warning("Failed to check for update", e);
|
LOG.warning("Failed to check for update", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,9 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
|
|
||||||
ArrayList<IOException> exceptions = null;
|
ArrayList<IOException> exceptions = null;
|
||||||
|
|
||||||
for (int retryTime = 0; retryTime < retry; retryTime++) {
|
// If loading the cache fails, the cache should not be loaded again.
|
||||||
|
boolean useCachedResult = true;
|
||||||
|
for (int retryTime = 0, retryLimit = retry; retryTime < retryLimit; retryTime++) {
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
throw new InterruptedException();
|
throw new InterruptedException();
|
||||||
}
|
}
|
||||||
@@ -204,7 +206,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
|
|
||||||
LinkedHashMap<String, String> headers = new LinkedHashMap<>();
|
LinkedHashMap<String, String> headers = new LinkedHashMap<>();
|
||||||
headers.put("accept-encoding", "gzip");
|
headers.put("accept-encoding", "gzip");
|
||||||
if (checkETag)
|
if (useCachedResult && checkETag)
|
||||||
headers.putAll(repository.injectConnection(uri));
|
headers.putAll(repository.injectConnection(uri));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@@ -248,7 +250,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
int responseCode = response.statusCode();
|
int responseCode = response.statusCode();
|
||||||
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
if (useCachedResult && responseCode == HttpURLConnection.HTTP_NOT_MODIFIED) {
|
||||||
// Handle cache
|
// Handle cache
|
||||||
try {
|
try {
|
||||||
Path cache = repository.getCachedRemoteFile(currentURI, false);
|
Path cache = repository.getCachedRemoteFile(currentURI, false);
|
||||||
@@ -260,9 +262,10 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warning("Unable to use cached file, redownload " + NetworkUtils.dropQuery(uri), e);
|
LOG.warning("Unable to use cached file, redownload " + NetworkUtils.dropQuery(uri), e);
|
||||||
repository.removeRemoteEntry(currentURI);
|
repository.removeRemoteEntry(currentURI);
|
||||||
|
useCachedResult = false;
|
||||||
// Now we must reconnect the server since 304 may result in empty content,
|
// Now we must reconnect the server since 304 may result in empty content,
|
||||||
// if we want to redownload the file, we must reconnect the server without etag settings.
|
// if we want to redownload the file, we must reconnect the server without etag settings.
|
||||||
retryTime--;
|
retryLimit++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else if (responseCode / 100 == 4) {
|
} else if (responseCode / 100 == 4) {
|
||||||
|
|||||||
Reference in New Issue
Block a user