Solved Main thread failed crash

Discussion in 'Plugin Development' started by CoolDude53, Jul 15, 2015.

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

    CoolDude53

    No clue why this is happening, but here is the stacktrace on the crash. I looked through the nms code, but couldn't come up with why anything I was doing in my plugin would cause this. I'd much appreciate any help from someone who knows more about the inner workings of minecraft. Thanks!

    Code:
    [Thread-13/WARN]: [Server] The main thread failed to respond after 10 seconds
    [01:40:07] [Thread-13/WARN]: [Server] What follows is the stack trace of the main thread
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.World.getEntities(World.java:2297)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.World.getCubes(World.java:1099)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.Entity.move(Entity.java:450)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityLiving.e(EntityLiving.java:1305)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityHuman.e(EntityHuman.java:1284)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityLiving.e(EntityLiving.java:1565)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityHuman.e(EntityHuman.java:390)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityLiving.h(EntityLiving.java:1398)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityHuman.h(EntityHuman.java:162)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.EntityPlayer.i(EntityPlayer.java:241)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:344)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.PacketPlayInFlying.a(SourceFile:137)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.PacketPlayInLook.handle(SourceFile:98)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469)
    [01:40:07] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)
    [01:40:19] [Thread-13/WARN]: [Server] The main thread is still stuck, current loop line is:
    [01:40:19] [Thread-13/WARN]: [Server]     at net.minecraft.server.v1_7_R4.Entity.move(Entity.java:450)
    [12:31:34] [Thread-4/INFO]: Stopping server
     
  2. Offline

    teej107

    @CoolDude53 Does this happen frequently or can it be recreated easily?
     
  3. Offline

    CoolDude53

    @teej107

    I have never been able to recreate it on demand. It has happened 30 minutes after starting my server, and it has happened 5 days of running smoothly. When it happens, there are no other events (like a player logging out, or my plugin doing a database sync) happening close enough that would make me believe it could have been triggered by something. I have made everything in my PlayerMoveEvent async, and I remove all hostile living entities from chunks when they are unloaded through the vanilla system. The issue is that I don't know what triggers it, so I have no way to debug or even check if it is resolved.
     
  4. Offline

    teej107

    Do they use Bukkit methods?
     
  5. Offline

    CoolDude53

    No. I converted them to async tasks because it was happening.
     
  6. Offline

    teej107

    @CoolDude53 Do you have the code that you suspect is causing this?
     
  7. Offline

    CoolDude53

    Well the thing is I thought it would be in the move event, but that isn't it. My next suspicion is something that get's all the entities in the world, but when I looked through the nms, I couldn't exactly tell what was triggering the call to get all the entities.
     
  8. Offline

    mythbusterma

    @CoolDude53

    Let's see your asynchronous tasks, I'm willing to bet you're severely violating the thread safety of the server if you just changed all of them to "async" without actually thinking about/understanding what you were doing.
     
  9. Offline

    CoolDude53

    Do you trust me now? I wouldn't have come here if I hadn't exhausted all the other conclusions I could had come up with.
    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event)
        {
            UUID uuid = event.getPlayer().getUniqueId();
            Location loc = event.getTo();
    
            if (!loc.getBlock().getLocation().equals(event.getFrom().getBlock().getLocation()))
            {
                new BukkitRunnable()
                {
                    @Override
                    public void run()
                    {
                        PlayerMechanics.playerLocs.put(uuid, loc);
    
                        if (Logout.logoutMap.containsKey(uuid))
                            Logout.logoutMap.remove(uuid);
                    }
                }.runTaskAsynchronously(Setup.plugin);
            }
        }
    }
    Code:
        @EventHandler
        public void onPlayerMove(PlayerMoveEvent event)
        {
            Player player = event.getPlayer();
            UUID uuid = event.getPlayer().getUniqueId();
            Location to = event.getTo().getBlock().getLocation();
            Location from = event.getFrom().getBlock().getLocation();
    
    
            if (summoningMountMap.containsKey(uuid) && !to.equals(from))
            {
                new BukkitRunnable()
                {
                    @Override
                    public void run()
                    {
                        summoningMountMap.remove(uuid);
                    }
                }.runTaskAsynchronously(Setup.plugin);
            }
        }
     
    Last edited: Jul 15, 2015
  10. Offline

    teej107

    @CoolDude53 Do you really need to remove those values from the Map in an asynchronous task? Srsly! Don't do that because you don't need to. Are you sure it's your plugin causing this? Try removing it from your server and see what happens.
     
  11. Offline

    CoolDude53

    No, there's no reason to lol, but they are the only derivatives I could think of that would cause it to freeze up the main thread. I will try that, but I have no clue how to reproduce it, so no way to actually check if it has stopped.
     
  12. Offline

    mythbusterma

    @CoolDude53

    Doing anything that requires the Bukkit API on the main thread may cause it to freeze, post all your asynchronous tasks.

    The code you've posted shows that you are very clearly violating the thread safety of the server.
     
  13. Offline

    CoolDude53

    Really? My whole 4 lines of async violates thread safety? Lol, stop acting like this is a simple problem that is caused by violating thread safety. These async tasks only put data in thread safe data structures, and the issue occurred even before I made them async in the first place. I have worked with issues that stem from async threads. I'm looking for information that I couldn't find anywhere else, and I know that most of the frequenters here have some incite that I didn't already come up with.

    This problem is difficult to track down because something is triggering the server to gather all the entities and for some reason it freezes up on that, making me believe that it is an issue with a corrupt chunk or something along those lines that would throw some unexpected information to the server. I posted this question to see if anyone here has either experienced an issue like this or knows more about the core nms code and could provide some incite to what is being called when this is happening, because if it is a simple player move event then I'm out of ideas, but if it is something else then maybe there is somewhere else I can look for faulty code.

    Thanks for your help, but unless you are here to explain or share your own experiences, your input isn't needed; go to any of the hundreds of other threads that are asking for your impeccable critique on their code.
     
    Last edited: Jul 17, 2015
  14. Offline

    mythbusterma

    @CoolDude53

    I have explained as much as I can without seeing your code. If you're using ConcurrentHashMaps, then I apologize for being rash.

    It is quite likely that this is a problem caused by violating thread safety. The server gets very upset when you mess with entities on other threads.

    If you don't believe that's the issue, then post your code. We can't help you if you don't.

    You expect us to help without posting any of your code. The most we can do in that case is operate off of assumptions, and judging by your inappropriate use of statics, that would lead one to assume, furthermore, you created an asynchronous task just to perform one simple remove operation, which is excessive.
     
  15. Offline

    CoolDude53

    I am indeed, as well as CopyOnWriteArrayLists. I can post any probable problem sections, but I have 33k lines of code...lol. I've seen thread safety crashes, and this isn't like one. Do you have any ideas for other areas to look besides the PlayerMoveEvent?
     
  16. Offline

    teej107

    @CoolDude53 Maybe I missed where you answered the question that I asked but are you 100% sure it is your plugin causing the problem?
     
  17. Offline

    CoolDude53

    Yes. I didn't get this before a certain point in development. The biggest problem is that I have no way of reproducing it. The server hasn't crashed for 3 days. The problem with this crash is it doesn't point directly to anything I did, but I know that it is something I did.
     
  18. Offline

    xTrollxDudex

    Challenge accepted
     
  19. Offline

    CoolDude53

    Lol, any ideas where to look next troll?
     
  20. Offline

    CoolDude53

    After a solid 2 months of being plagued with this issue, a random alpha tester stumbled upon the cause. I am still unsure of what exactly triggered it, but it had to do with mobs teleporting to a player's exact location while standing on an elevated block...I know, it sounds odd and completely unrelated to what was provided in the crash report. My best guess is that it tried to push the player when being teleported and something in the minecraft code didn't like that. Thanks for trying to help guys!
     
  21. Offline

    SuperOriginal

    Glad you finally figured it out.
     
Thread Status:
Not open for further replies.

Share This Page