Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -44,6 +44,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -381,7 +382,9 @@ private boolean shouldRetryDownload(IOException e, int attempt) {
}

private boolean isRetryableException(Throwable e) {
return e instanceof ContentLengthMismatchException || e instanceof SocketException;
return e instanceof ContentLengthMismatchException
|| e instanceof SocketException
|| e instanceof UnknownHostException;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ URLConnection connect(
} catch (UnknownHostException e) {
String message = "Unknown host: " + e.getMessage();
eventHandler.handle(Event.progress(message));
throw new UnrecoverableHttpException(message);
IOException httpException = new UnrecoverableHttpException(message);
httpException.addSuppressed(e);
throw httpException;
Comment on lines +161 to +163

Choose a reason for hiding this comment

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

critical

The retry logic in DownloadManager.shouldRetryDownload inspects the exception's cause chain to find a retryable exception. Using addSuppressed(e) will not place the original UnknownHostException in the cause chain, so it won't be detected for a retry.

To ensure the exception can be caught by the retry logic, you should use initCause(e) to properly chain the exceptions.

Suggested change
IOException httpException = new UnrecoverableHttpException(message);
httpException.addSuppressed(e);
throw httpException;
IOException httpException = new UnrecoverableHttpException(message);
httpException.initCause(e);
throw httpException;

} catch (IllegalArgumentException e) {
// This will happen if the user does something like specify a port greater than 2^16-1.
throw new UnrecoverableHttpException(e.getMessage());
Expand Down
Loading