NBT-API

NBT-API

98.9k Downloads

Server freezes on join

fan87 opened this issue ยท 11 comments

commented

When I tried to use addCompound(String) it sometimes freezes my server, and I set the timeOut to 20, and I got a thread dump saying that it was trying to do getType(), and the server just froze.
Full thread dump is included in the attachment, Spigot version 1.8 build db6de12-18fbb24. I'm also using Greenrobot's EventBus API, I don't know if that causes the issue.
I'm bad at multi threading and stuff, so I can't understand it, it's probably deadlock, but I don't really know, cuz I don't know how to read the thread dump

threaddumps.txt
.

commented

It says

[19:55:02 INFO]: [NBTAPI] Found Spigot: v1_8_R3! Trying to find NMS support
[19:55:02 INFO]: [NBTAPI] NMS support 'MC1_8_R3' loaded!
[19:55:02 INFO]: [NBTAPI] Found Gson: class com.google.gson.Gson
[19:55:02 INFO]: [NBTAPI] Using the plugin 'LuckPerms' to create a bStats instance!

normally

but If I join before server ready, it won't say:

[19:55:02 INFO]: [NBTAPI] Using the plugin 'LuckPerms' to create a bStats instance!

Also, I'm getting NBT of player's inventory item

commented

More info: It happens when the server is starting, while its starting, you can still join the game. If I join like 10 seconds later it seems not happening

commented

Ya I know I didn't relocate cuz I'm not using maven for now, I'm building with intellij cuz maven takes too long, it will be changed if I want to release the plugin

And I'm not sure if it's a 1.8 bug, cuz I don't think server is fully started at that moment. I'll add more debugging stuff, and send full log if it happens again.

commented

To the thread dump:
The main thread is apparently running, so might be that it's stuck in an infinite loop of creating items or something, and the first netty thread for whatever reason is trying to async initialize the metrics and is stuck at getting the plugin list.
My guess is that stuff gets called while plugins are still loading/the server isn't done, causing a deadlock because of this invalid state.

commented

Not sure what Greenrobot's EventBus API does, but being able to join and trigger events before the server is done loading sounds like a 1.8 bug? Also note that you haven't setup shading correctly de.tr7zw.changeme.nbtapi.

commented

The EventBus API seems to work on a packet base and ignore the save Spigot API logic. Try to not use it for stuff like Player Join events, the spigot API will hold back that event till the server is done and the player actually joining.

commented

The EventBus API seems to work on a packet base and ignore the save Spigot API logic. Try to not use it for stuff like Player Join events, the spigot API will hold back that event till the server is done and the player actually joining.

It's an event bus api, just like google's, but improved. I have a event listener that re-posts events to that eventbus
What I'm not sure is I don't know if it runs on main thread or not
Here's the code

        Reflections reflections = new Reflections("org.bukkit.event");
        for (Class<? extends Event> eventClazz : reflections.getSubTypesOf(Event.class)) {
            try {
                eventClazz.getDeclaredMethod("getHandlerList");
            } catch (Exception e) {
                continue;
            }
            instance.getServer().getPluginManager().registerEvent(eventClazz, new Listener() {
            }, EventPriority.NORMAL, new EventExecutor() {
                @Override
                public void execute(Listener listener, Event event) throws EventException {
                    EVENT_BUS.post(event);
                }
            }, instance);
        }

It's better than bukkit's event api, so I decided to use this instead, and if I need custom events I won't need to extends Event or do something like that.

Here's where player join is handled:

    @Subscribe
    public void onJoin(PlayerJoinEvent event) {
        addPlayer(event.getPlayer());
    }
commented

It is on the main thread, that's not the direct issue. The issue is that this event gets handeled when it should not. Try to use Spigots Event API, and not an unsafe 3rd party one. If that happens in with the normal api too, then this is a 1.8 bug.

commented

It is on the main thread, that's not the direct issue. The issue is that this event gets handeled when it should not. Try to use Spigots Event API, and not an unsafe 3rd party one. If that happens in with the normal api too, then this is a 1.8 bug.

I'll test it later.
After testing I can't not join before server starts, but if I join right after server starts, there's like 50% chance my server is going to freeze, still not sure why.

commented

(I'm bad at English)

I tried the spigot event api, but unfortunately it still happens. Now, the server freezes between 2 messages (I'll talk about it in later of the comment).
First, using raw NMS fixes the issue, at least it doesn't freeze the server till now.
Second, still have no idea why, and I'll debug the api iteself later, and see which line freezes it.
Third, everything is on main thread now.
For now, inventory are being updated once a packet with ItemStack array or single ItemStack is being sent, and inventory update basically means it will give every single item in player's inventory a nbt tag. Here's what I think:

  1. Player join the server
  2. Update inventory once, and applied NBT once
  3. Send message A
  4. Teleport the player to another world
  5. Update inventory again (Since switch world will cause S30PacketWindowItems being sent) <- This freezes the server in addCompound()
  6. Send message B (Not being sent since the server is frozen already)
commented

I'll close the issue since this isn't really nbtapi related and there is nothing to do/fix from my end.