Skip to content

Rollback to official source when any errors occur in the image #6636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: v3_openjdk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -12,6 +12,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.SocketException;
import java.net.UnknownHostException;

public class DownloadMirror {
public static final int DOWNLOAD_CLASS_LIBRARIES = 0;
Expand Down Expand Up @@ -41,7 +43,8 @@ public static void downloadFileMirrored(int downloadClass, String urlInput, File
DownloadUtils.downloadFileMonitored(getMirrorMapping(downloadClass, urlInput),
outputFile, buffer, monitor);
return;
}catch (FileNotFoundException e) {
}catch (FileNotFoundException | SocketException /* Connection Reset and java.net.ConnectException */
| UnknownHostException e) {
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
Log.i("DownloadMirror", "Falling back to default source");
}
Expand All @@ -61,7 +64,8 @@ public static void downloadFileMirrored(int downloadClass, String urlInput, File
DownloadUtils.downloadFile(getMirrorMapping(downloadClass, urlInput),
outputFile);
return;
}catch (FileNotFoundException e) {
} catch (FileNotFoundException | SocketException /* Connection Reset and java.net.ConnectException */
| UnknownHostException e) {
Log.w("DownloadMirror", "Cannot find the file on the mirror", e);
Log.i("DownloadMirror", "Falling back to default source");
}
Expand All @@ -78,7 +82,7 @@ public static void downloadFileMirrored(int downloadClass, String urlInput, File
*/
public static long getContentLengthMirrored(int downloadClass, String urlInput) throws IOException {
long length = DownloadUtils.getContentLength(getMirrorMapping(downloadClass, urlInput));
if(length < 1) {
if (length < 1) {
Log.w("DownloadMirror", "Unable to get content length from mirror");
Log.i("DownloadMirror", "Falling back to default source");
return DownloadUtils.getContentLength(urlInput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public static void download(String url, OutputStream os) throws IOException {
}

public static void download(URL url, OutputStream os) throws IOException {
InputStream is = null;
try {
// System.out.println("Connecting: " + url.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Expand All @@ -30,21 +29,16 @@ public static void download(URL url, OutputStream os) throws IOException {
conn.setDoInput(true);
conn.connect();
if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("Server returned HTTP " + conn.getResponseCode()
// We may be on the mirror, just give it a chance to rollback to official
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment should not be there. download is a general purpose function.

Suggestion: remove the comment

Copy link
Author

Choose a reason for hiding this comment

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

Removed comment

throw new SocketException("Server returned HTTP " + conn.getResponseCode()
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong Exception kind, as on a technical level, the communication was executed successfully.

Suggestion: Create an alternate Exception type like HttpException

Copy link
Author

Choose a reason for hiding this comment

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

Created HttpException

+ ": " + conn.getResponseMessage());
}
is = conn.getInputStream();
IOUtils.copy(is, os);
} catch (IOException e) {
throw new IOException("Unable to download from " + url, e);
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
e.printStackTrace();
}
try (InputStream is = conn.getInputStream()) {
IOUtils.copy(is, os);
}
} catch (IOException e) { // Here Is Socket Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: remove comment

Copy link
Author

Choose a reason for hiding this comment

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

removed comment

Log.w("DownloadUtils", "Unable to download from " + url, e);
throw e;
}
}

Expand Down