Log Minecraft Internal Scheduler logs correctly

This commit is contained in:
Aikar 2020-06-28 05:34:23 -04:00
parent e4d10c3cdf
commit 86ee6c968c
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
5 changed files with 50 additions and 38 deletions

View file

@ -4471,7 +4471,7 @@ index 6a797a0ac8ca3f120eea5bd9c54de21a4f38b257..f1c4ae9997d5d11d903360dbccf45f3c
/**
* Mirror
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 9ad17c560c8d99a396543ab9f97c34de648f6544..533c0bc55fc7ac4cc1f493f898a85a6617371031 100644
index 9ad17c560c8d99a396543ab9f97c34de648f6544..4bf48f77f3f7cd62a91590543f5af441c8268029 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -43,6 +43,7 @@ import org.bukkit.scheduler.BukkitWorker;
@ -4494,6 +4494,32 @@ index 9ad17c560c8d99a396543ab9f97c34de648f6544..533c0bc55fc7ac4cc1f493f898a85a66
public BukkitTask runTaskTimer(Plugin plugin, Object runnable, long delay, long period) {
validate(plugin, runnable);
if (delay < 0L) {
@@ -400,13 +406,20 @@ public class CraftScheduler implements BukkitScheduler {
task.run();
task.timings.stopTiming(); // Spigot
} catch (final Throwable throwable) {
- task.getOwner().getLogger().log(
+ // Paper start
+ String msg = String.format(
+ "Task #%s for %s generated an exception",
+ task.getTaskId(),
+ task.getOwner().getDescription().getFullName());
+ if (task.getOwner() == MINECRAFT) {
+ net.minecraft.server.MinecraftServer.LOGGER.error(msg, throwable);
+ } else {
+ task.getOwner().getLogger().log(
Level.WARNING,
- String.format(
- "Task #%s for %s generated an exception",
- task.getTaskId(),
- task.getOwner().getDescription().getFullName()),
+ msg,
throwable);
+ }
+ // Paper end
} finally {
currentTask = null;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
index 3f55381c152b9841b524f623c9b32360e97cb8ed..d85e21b75054067b926ecfee89d62c6dd0744189 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java

View file

@ -1982,7 +1982,7 @@ index c5216d62660631f54d50575c30717f4052c10f8f..661c8b3c81be46ef2c9488bb52d1963c
public Player.Spigot spigot()
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 533c0bc55fc7ac4cc1f493f898a85a6617371031..de332758e03a563a9b72c134332db9e6a1c5ed2b 100644
index 4bf48f77f3f7cd62a91590543f5af441c8268029..ffe9cc1011226d604dc5499e7692e9a9a5132b72 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -1,5 +1,6 @@
@ -2028,9 +2028,9 @@ index 533c0bc55fc7ac4cc1f493f898a85a6617371031..de332758e03a563a9b72c134332db9e6
task.run();
- task.timings.stopTiming(); // Spigot
} catch (final Throwable throwable) {
task.getOwner().getLogger().log(
Level.WARNING,
@@ -431,8 +431,10 @@ public class CraftScheduler implements BukkitScheduler {
// Paper start
String msg = String.format(
@@ -438,8 +438,10 @@ public class CraftScheduler implements BukkitScheduler {
runners.remove(task.getTaskId());
}
}
@ -2041,7 +2041,7 @@ index 533c0bc55fc7ac4cc1f493f898a85a6617371031..de332758e03a563a9b72c134332db9e6
debugHead = debugHead.getNextHead(currentTick);
}
@@ -465,6 +467,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -472,6 +474,7 @@ public class CraftScheduler implements BukkitScheduler {
}
private void parsePending() {
@ -2049,7 +2049,7 @@ index 533c0bc55fc7ac4cc1f493f898a85a6617371031..de332758e03a563a9b72c134332db9e6
CraftTask head = this.head;
CraftTask task = head.getNext();
CraftTask lastTask = head;
@@ -483,6 +486,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -490,6 +493,7 @@ public class CraftScheduler implements BukkitScheduler {
task.setNext(null);
}
this.head = lastTask;

View file

@ -253,7 +253,7 @@ index 19e68a78310de787bca701bc2597c64e34a77d7c..a2a25cf6a43a1f59a80c997e2980f2bb
} finally {
if (pushbackinputstream != null) {
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index de332758e03a563a9b72c134332db9e6a1c5ed2b..e68533176a0c07560118531600304fa76a1c3fc6 100644
index ffe9cc1011226d604dc5499e7692e9a9a5132b72..343cdb06881fa8b0155b56d29c110bba489f9667 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -16,6 +16,9 @@ import java.util.concurrent.atomic.AtomicInteger;
@ -266,30 +266,16 @@ index de332758e03a563a9b72c134332db9e6a1c5ed2b..e68533176a0c07560118531600304fa7
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.Plugin;
@@ -406,20 +409,26 @@ public class CraftScheduler implements BukkitScheduler {
try {
task.run();
} catch (final Throwable throwable) {
+ // Paper start
+ String msg = String.format(
+ "Task #%s for %s generated an exception",
+ task.getTaskId(),
+ task.getOwner().getDescription().getFullName());
task.getOwner().getLogger().log(
Level.WARNING,
- String.format(
- "Task #%s for %s generated an exception",
- task.getTaskId(),
- task.getOwner().getDescription().getFullName()),
+ msg,
@@ -419,6 +422,8 @@ public class CraftScheduler implements BukkitScheduler {
msg,
throwable);
}
+ task.getOwner().getServer().getPluginManager().callEvent(
+ new ServerExceptionEvent(new ServerSchedulerException(msg, throwable, task))
+ );
+ // Paper end
+ new ServerExceptionEvent(new ServerSchedulerException(msg, throwable, task)));
// Paper end
} finally {
currentTask = null;
}
@@ -426,7 +431,7 @@ public class CraftScheduler implements BukkitScheduler {
parsePending();
} else {
debugTail = debugTail.setNext(new CraftAsyncDebugger(currentTick + RECENT_TICKS, task.getOwner(), task.getTaskClass()));

View file

@ -9,10 +9,10 @@ One report of a suspected memory leak with the system.
This adds additional overhead to asynchronous task dispatching
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index e68533176a0c07560118531600304fa76a1c3fc6..ff855035ae55df37d68b284ac18976c46d388af2 100644
index 343cdb06881fa8b0155b56d29c110bba489f9667..f7a977c342e564b3e24034c756c128068c143a65 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -427,7 +427,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -430,7 +430,7 @@ public class CraftScheduler implements BukkitScheduler {
}
parsePending();
} else {
@ -21,7 +21,7 @@ index e68533176a0c07560118531600304fa76a1c3fc6..ff855035ae55df37d68b284ac18976c4
executor.execute(new ServerSchedulerReportingWrapper(task)); // Paper
// We don't need to parse pending
// (async tasks must live with race-conditions if they attempt to cancel between these few lines of code)
@@ -444,7 +444,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -447,7 +447,7 @@ public class CraftScheduler implements BukkitScheduler {
pending.addAll(temp);
temp.clear();
MinecraftTimings.bukkitSchedulerFinishTimer.stopTiming();
@ -30,7 +30,7 @@ index e68533176a0c07560118531600304fa76a1c3fc6..ff855035ae55df37d68b284ac18976c4
}
private void addTask(final CraftTask task) {
@@ -504,10 +504,15 @@ public class CraftScheduler implements BukkitScheduler {
@@ -507,10 +507,15 @@ public class CraftScheduler implements BukkitScheduler {
@Override
public String toString() {

View file

@ -159,7 +159,7 @@ index 0000000000000000000000000000000000000000..3c1992e212a6d6f1db4d5b807b38d719
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025820de2c3 100644
index f7a977c342e564b3e24034c756c128068c143a65..7532bbd82559763cfaf5433a07914b5fb906122c 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -63,7 +63,7 @@ public class CraftScheduler implements BukkitScheduler {
@ -315,7 +315,7 @@ index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025
this.currentTick = currentTick;
final List<CraftTask> temp = this.temp;
parsePending();
@@ -428,7 +486,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -431,7 +489,7 @@ public class CraftScheduler implements BukkitScheduler {
parsePending();
} else {
//debugTail = debugTail.setNext(new CraftAsyncDebugger(currentTick + RECENT_TICKS, task.getOwner(), task.getTaskClass())); // Paper
@ -324,7 +324,7 @@ index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025
// We don't need to parse pending
// (async tasks must live with race-conditions if they attempt to cancel between these few lines of code)
}
@@ -447,7 +505,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -450,7 +508,7 @@ public class CraftScheduler implements BukkitScheduler {
//debugHead = debugHead.getNextHead(currentTick); // Paper
}
@ -333,7 +333,7 @@ index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025
final AtomicReference<CraftTask> tail = this.tail;
CraftTask tailTask = tail.get();
while (!tail.compareAndSet(tailTask, task)) {
@@ -456,7 +514,13 @@ public class CraftScheduler implements BukkitScheduler {
@@ -459,7 +517,13 @@ public class CraftScheduler implements BukkitScheduler {
tailTask.setNext(task);
}
@ -348,7 +348,7 @@ index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025
task.setNextRun(currentTick + delay);
addTask(task);
return task;
@@ -475,8 +539,8 @@ public class CraftScheduler implements BukkitScheduler {
@@ -478,8 +542,8 @@ public class CraftScheduler implements BukkitScheduler {
return ids.incrementAndGet();
}
@ -359,7 +359,7 @@ index ff855035ae55df37d68b284ac18976c46d388af2..99ea0aabadfac2a68ec67a7d49831025
CraftTask head = this.head;
CraftTask task = head.getNext();
CraftTask lastTask = head;
@@ -495,7 +559,7 @@ public class CraftScheduler implements BukkitScheduler {
@@ -498,7 +562,7 @@ public class CraftScheduler implements BukkitScheduler {
task.setNext(null);
}
this.head = lastTask;