Add information about async tasks to CrashReports. Addresses BUKKIT-2491
Async tasks are notorious for causing CMEs and corrupted data when accessing the API. This change makes a linked list to track recent tasks that may no longer be running. It is accessed via the toString method on the scheduler. This behavior is not guaranteed, but it is accessible as such currently. Although toString is located in the scheduler, its contract does not guarantee an accurate or up to date call when accessed from a second thread.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package org.bukkit.craftbukkit.scheduler;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
class CraftAsyncDebugger {
|
||||
private CraftAsyncDebugger next = null;
|
||||
private final int expiry;
|
||||
private final Plugin plugin;
|
||||
private final Class<? extends Runnable> clazz;
|
||||
|
||||
CraftAsyncDebugger(final int expiry, final Plugin plugin, final Class<? extends Runnable> clazz) {
|
||||
this.expiry = expiry;
|
||||
this.plugin = plugin;
|
||||
this.clazz = clazz;
|
||||
|
||||
}
|
||||
|
||||
final CraftAsyncDebugger getNextHead(final int time) {
|
||||
CraftAsyncDebugger next, current = this;
|
||||
while (time > current.expiry && (next = current.next) != null) {
|
||||
current = next;
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
final CraftAsyncDebugger setNext(final CraftAsyncDebugger next) {
|
||||
return this.next = next;
|
||||
}
|
||||
|
||||
StringBuilder debugTo(final StringBuilder string) {
|
||||
for (CraftAsyncDebugger next = this; next != null; next = next.next) {
|
||||
string.append(plugin.getDescription().getName()).append(':').append(clazz.getName()).append('@').append(expiry).append(',');
|
||||
}
|
||||
return string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user