OutOfBounds Causing Server Crash

Discussion in 'Plugin Development' started by spy85, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    spy85

    My server continues to crash on the same exception every time in my WorldWarZ plugin I have created:

    Code:
    # ftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    [19:27:40] [Server thread/INFO]: TPS: 13.0Free Memory: 1683MB
    [19:27:40] [Server thread/WARN]: [WorldWarZ] Task #33606260 for WorldWarZ v2.4 generated an exception
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604) ~[?:1.7.0_17]
    at java.util.ArrayList.get(ArrayList.java:382) ~[?:1.7.0_17]
    at Memory.MemoryManagement$MemoryChecker.run(MemoryManagement.java:60) ~[?:?]
    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftTask.run(CraftTask.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:587) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    [19:27:40] [Server thread/INFO]: TPS: 13.0Free Memory: 1683MB
    [19:27:40] [Server thread/WARN]: [WorldWarZ] Task #33606261 for WorldWarZ v2.4 generated an exception
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:604) ~[?:1.7.0_17]
    at java.util.ArrayList.get(ArrayList.java:382) ~[?:1.7.0_17]
    at Memory.MemoryManagement$MemoryChecker.run(MemoryManagement.java:60) ~[?:?]
    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftTask.run(CraftTask.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:587) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-3-g530fcb7-b2979jnks]
    Why does an exception as simple as this crash the server? Thanks.
     
  2. Offline

    xTigerRebornx

    spy85 Its not the exception, its the number of tasks you have scheduled
    Snippet of the stacktrace
    Code:
     Task #33606260 for WorldWarZ v2.4 generated an exception
    You have over 33million tasks scheduled.....
     
  3. Offline

    turt2live

    Not to mention the error is quite clear:

    Due to the change, and lack, of package naming, I can only assume "Memory.MemoryManagement" is your plugin. Which, if it is, I suggest you look at package naming conventions as well.
     
  4. Offline

    spy85

    Doesn't a task stop and go away once its finished? I mean I have tasks going every few mili seconds and repeating themselves within themselves so that makes sense. Thanks so much I'll fix it!

    By the way is it possible to use wait(long) in a BukkitTask or Thread.sleep(long) ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    Gater12

    spy85
    Nope. Unless you want to freeze your server.
     
  6. Offline

    spy85

    What happens to a BukkitRunnable or BukkitTask that I do not cancel? Apparently I have over 3million bukkit tasks running so by canceling them when they're done would this stop the tasks being at 3million? Because I have tasks repeating over and over.
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    It depends. Without the source code, no one can say for certain.
     
  8. Offline

    turt2live

    The ID is not reused, but usually when you hit 33 million you are doing something weird/wrong.
    ^ Will indeed help in identifying the issue(s), such as the 33 million tasks.
     
  9. Offline

    spy85

    turt2live @ Sagacious_Zed Gater12
    Here is an example of one of the many tasks I have in use:
    Code:java
    1. private final int voteCancelSecs = 28;
    2. private int passedSecs = 0;
    3. private void repeatVoteTimeLeft(){
    4. if(voteIsOn){
    5. new VoteTimeLeft().runTaskLater(plugin, 20*1);
    6. }
    7. }
    8. private class VoteTimeLeft extends BukkitRunnable {
    9. public void run(){
    10. passedSecs += 1;
    11. if(passedSecs >= voteCancelSecs && voteIsOn){
    12. plugin.getServer().broadcastMessage(chatPrefix + ChatColor.RED + ChatColor.BOLD + "Vote for next round has timed out!");
    13. endVote();
    14. }else if(voteIsOn){
    15. repeatVoteTimeLeft();
    16. }
    17. }
    18. }

    What other source code do you need? This is the format in which I run BukkitRunnables usually and repeat them. What am I doing wrong that could be causing 33million? Some BukkitRunnables work the same way as this but repeat every few miliseconds.
     
  10. Offline

    turt2live

    You create a new task every 1 second so long as "voteIsOn" is true.
     
  11. Offline

    spy85

    Right so when I'm done with a task how do I completely remove it so they don't keep adding up and eventually ending up as 33 mil? Will just cancling it at the end work?
     
  12. Offline

    Garris0n

    Yes, if you cancel them you won't end up with that many.
     
  13. Offline

    Sagacious_Zed Bukkit Docs

    It doesn't matter, as long as you create a new one, the counter will increment. For example, even if task #1 is destroyed, you have already created task #2.
     
  14. Offline

    spy85

    Is it mandatory that you cancel a task when done with it? What does canceling actually do though?

    Right but if I do not cancel the task #1 then task #1 and task #2 combined make 2 tasks but if I do cancel task #1 then there is just task #2 which makes 1 task is that how it will work? So Basically canceling tasks when done with them will do the trick?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  15. Offline

    Garris0n

    Looking at it, it might not even be the cancelling. You're just creating so many tasks...is that the only code related to tasks?
     
  16. Offline

    Sagacious_Zed Bukkit Docs

    It depends.
    If you run #1 later, it will execute once later creating task #2, then finish.
    In this particular case, #2 will run once, creating #3 then finishes.
    so on and so forth.

    If you run #1 later on a timer, it will execute once creating tasks #2, then put back onto the schedule.
    In this particular case, #2 executes once,create task #3 then finishes.
    and task #1 will make #4 when it executes as scheduled.
    and #3 will created task #5
    and so on and so forth.

    there is currently not enough context.
     
  17. Offline

    Alshain01

    spy85 You asked a question that I didn't see answered. Just to clarify, it is not necessary to cancel a BukkitRunnable if you are using runTaskLater (or runTask) AFTER it's execution. cancel will stop it before it's execution or is used to stop runTaskTimer. The Bukkit scheduler guide even shows an example of a non-self cancelling Anonymous BukkitRunnable. Since it's anonymous and doesn't cancel itself, there would be no way to get rid of it! Except it really does send itself to garbage collection.

    I think the reason you have so many is just because of the sheer number of tasks your scheduling.
     
  18. Offline

    spy85

    Oh thank you so much for your help and explanation that really helps! I do not start or even create all the threads at once and usually don't even save them in variables so how could there be 3 million all at once? I understand if 3 million have been created total but 3 million at once doesn't make any sense. Any idea how this happens?

    I have tons of classes each with plenty of Tasks but definitely not enough for 33 million.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  19. Offline

    Garris0n

    I would assume with a number like that it's something recursive that's multiplying the amount constantly.
     
  20. Offline

    turt2live

    This particular use case doesn't need so many threads though...
     
Thread Status:
Not open for further replies.

Share This Page