-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Rollback to official source when any errors occur in the image #6636
base: v3_openjdk
Are you sure you want to change the base?
Conversation
Hi there @f401, thank you for bringing your concern through a contribution. However, it would be preferable to know what kind of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handling regarding some exceptions leaves a bit to be desired.
For example, if one was to have the unknown host exception on a single file from a mirror, it is pretty much expected for said exception to resurface for every single file.
Suggestion: Make the DownloadMirror
class non-static and make it aware of the failures when trying to download from a mirror.
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed comment
@@ -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 | |||
throw new SocketException("Server returned HTTP " + conn.getResponseCode() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created HttpException
} | ||
} catch (IOException e) { // Here Is Socket Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed comment
According to https://github.com/bangbang93/openbmclapi. |
This is indeed right. However, my statement is right as well, but allow me to reformulate it for you: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somes changes have to be made, see my comment outside of the review as well.
|
||
public class HttpException extends IOException { | ||
// Do not change. Android really hates when this value changes for some reason. | ||
private static final long serialVersionUID = -7372301619612640655L; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Can you elaborate on why this line is here ?
In my limited testing, I failed to see what it changed.
// Do not change. Android really hates when this value changes for some reason. | ||
private static final long serialVersionUID = -7372301619612640655L; | ||
|
||
public HttpException(String msg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The Exception should take an http code accessible to the catch block of Exception
handlers.
@Mathias-Boulay import java.io.FileOutputStream
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
fun main() {
val url = "https://bmclapi2.bangbang93.com/version/1.7.10/client"
var hitCount = 0
var code: Int = -1;
do {
val connection =
URL(url).openConnection() as HttpURLConnection
try {
connection.connect()
code = connection.responseCode
++hitCount
val fos = FileOutputStream("/tmp/t.jar")
connection.inputStream.copyTo(fos)
fos.close()
} catch (e: IOException) {
e.printStackTrace()
}
connection.disconnect()
} while (code == HttpURLConnection.HTTP_OK)
println("Code $code, hit count $hitCount")
} result:
It can be seen that the probability of encountering a 404 error when downloading the same file is low. It also confirms that there may be issues with the child nodes. Here is also an unresolved issue with OpenBMCLAPI regarding the validation of HTTP Code availability for child nodes (written in Chinese) bangbang93/openbmclapi#8. My personal opinion: The above is due to implementation issues with the BMCLAPI source. It cannot be ruled out that other sources may be added in the future. Perhaps internal service errors in the download source can be resolved by rolling back the subsequent downloads to the official source (your suggestion) as a launcher preference option. |
No description provided.