From ed6aab8200f0f28219ea01306a6f8b62f66bcbb2 Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Sun, 23 Dec 2012 05:13:33 -0600 Subject: [PATCH] Remove runner leak on async tasks. Fixes BUKKIT-3288 In some situations, an async task could be cancelled with no tasks pending. This means the finally {} block from run() never gets executed properly on the last async task to have run, as it expected to be executed again. This fix takes the only spot that the task period is set to cancelled and will check to see if the task should be purged from the runners list. --- .../java/org/bukkit/craftbukkit/scheduler/CraftAsyncTask.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncTask.java index 75a1a63ab6..f3da84a920 100644 --- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncTask.java +++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftAsyncTask.java @@ -100,6 +100,9 @@ class CraftAsyncTask extends CraftTask { synchronized (workers) { // Synchronizing here prevents race condition for a completing task setPeriod(-2l); + if (workers.isEmpty()) { + runners.remove(getTaskId()); + } } return true; }