Skip to content

Commit

Permalink
Fix infinite loop during a reporting exception.
Browse files Browse the repository at this point in the history
An infinite loop was caused if stats.cereal.sh is not accessible or any other exception occurs during the reporting thread.  A try block was added to remove this possiblity.
  • Loading branch information
Morgan Humes committed Jan 19, 2012
1 parent 346e3c3 commit 8793f36
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions src/net/milkbowl/autosave/ReportThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,47 @@ public void run() {

while (true) {
try {
URL statsUrl = new URL(
String.format(
"%s?uuid=%s&plugin=%s&version=%s&bVersion=%s&osName=%s&osArch=%s&osVersion=%s&java=%s",
statsBaseUrl, URLEncoder.encode(
uuid.toString(), "ISO-8859-1"),
URLEncoder.encode(pluginName, "ISO-8859-1"),
URLEncoder.encode(pluginVersion, "ISO-8859-1"),
URLEncoder.encode(bukkitVersion, "ISO-8859-1"),
URLEncoder.encode(osName, "ISO-8859-1"),
URLEncoder.encode(osArch, "ISO-8859-1"),
URLEncoder.encode(osVersion, "ISO-8859-1"),
URLEncoder.encode(java, "ISO-8859-1")));
URLConnection conn = statsUrl.openConnection();
conn.setRequestProperty("User-Agent", String.format("%s %s:%s",
"BukkitReport", pluginName, pluginVersion));
String inputLine;
BufferedReader in = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
try {
URL statsUrl = new URL(
String.format(
"%s?uuid=%s&plugin=%s&version=%s&bVersion=%s&osName=%s&osArch=%s&osVersion=%s&java=%s",
statsBaseUrl,
URLEncoder.encode(uuid.toString(),
"ISO-8859-1"),
URLEncoder.encode(pluginName, "ISO-8859-1"),
URLEncoder.encode(pluginVersion,
"ISO-8859-1"), URLEncoder.encode(
bukkitVersion, "ISO-8859-1"),
URLEncoder.encode(osName, "ISO-8859-1"),
URLEncoder.encode(osArch, "ISO-8859-1"),
URLEncoder.encode(osVersion, "ISO-8859-1"),
URLEncoder.encode(java, "ISO-8859-1")));
URLConnection conn = statsUrl.openConnection();
conn.setRequestProperty("User-Agent", String.format(
"%s %s:%s", "BukkitReport", pluginName,
pluginVersion));
String inputLine;
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));

if (debug) {
// Output the contents -- wee
log.info(String.format("[%s] StatsURL: %s", pluginName,
statsUrl.toString()));
while ((inputLine = in.readLine()) != null) {
if (inputLine.equals("<pre>")
|| inputLine.equals("</pre>")) {
continue;
if (debug) {
// Output the contents -- wee
log.info(String.format("[%s] StatsURL: %s", pluginName,
statsUrl.toString()));
while ((inputLine = in.readLine()) != null) {
if (inputLine.equals("<pre>")
|| inputLine.equals("</pre>")) {
continue;
}
log.info(String.format("[%s] %s", pluginName,
inputLine));
}
log.info(String
.format("[%s] %s", pluginName, inputLine));
}
}

in.close();
in.close();
} catch (Exception e) {
// care
}

// Sleep for 6 hours...
for (int i = 0; i < REPORT_DELAY; i++) {
Expand All @@ -121,8 +128,10 @@ public void run() {
}
Thread.sleep(1000);
}
} catch (Exception e) {
// Ignore it...really its just not important
} catch (InterruptedException e) {
// If this happens, lets stop reporting
setRun(false);
return;
}
}
}
Expand Down

0 comments on commit 8793f36

Please sign in to comment.