joserodpt / RealScoreboard

Source-code for the RealScoreboard spigot plugin.
MIT License
20 stars 16 forks source link

NPEs on disconnect #72

Closed SlimeDog closed 2 months ago

SlimeDog commented 4 months ago

Paper 1.20.6-49 RealScoreboard 1.4.2

I often see these errors on player disconnect

[16:32:39 WARN]: [RealScoreboard] Plugin RealScoreboard v1.4.2 generated an exception while executing task 1789
java.lang.NullPointerException: Cannot invoke "fr.mrmicky.fastboard.FastBoard.updateLines(java.util.Collection)" because the return value of "joserodpt.realscoreboard.api.scoreboard.RPlayerHook.access$300(joserodpt.realscoreboard.api.scoreboard.RPlayerHook)" is null
        at RealScoreboard-1.4.2.jar/joserodpt.realscoreboard.api.scoreboard.RPlayerHook$1.run(RPlayerHook.java:69) ~[RealScoreboard-1.4.2.jar:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.20.6.jar:git-Paper-49]
        at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.20.6.jar:git-Paper-49]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.20.6.jar:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]
[16:32:39 WARN]: [RealScoreboard] Plugin RealScoreboard v1.4.2 generated an exception while executing task 1788
java.lang.NullPointerException: Cannot invoke "fr.mrmicky.fastboard.FastBoard.updateLines(java.util.Collection)" because the return value of "joserodpt.realscoreboard.api.scoreboard.RPlayerHook.access$300(joserodpt.realscoreboard.api.scoreboard.RPlayerHook)" is null
        at RealScoreboard-1.4.2.jar/joserodpt.realscoreboard.api.scoreboard.RPlayerHook$1.run(RPlayerHook.java:69) ~[RealScoreboard-1.4.2.jar:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:101) ~[paper-1.20.6.jar:git-Paper-49]
        at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[paper-1.20.6.jar:git-Paper-49]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[paper-1.20.6.jar:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]
joserodpt commented 4 months ago

More logs? Couldn't reproduce this issue

SlimeDog commented 4 months ago

There are no other logged indicators.

Please handle the indicated NPE (Thread.java:1570). Code should never generate NPEs.

joserodpt commented 4 months ago

Can't really know where it's happening in the code, it says line 69 but there's no indication as to what could be. And obviously I can't guess what's throwing that NPE inside the Thread class. It must come from my code on line 69

SlimeDog commented 4 months ago

Can't really know where it's happening in the code, it says line 69 but there's no indication as to what could be. And obviously I can't guess what's throwing that NPE inside the Thread class. It must come from my code on line 69

If I had to guess, I would posit that fastBoard.updateLines(list) is trying to update a scoreboard that no longer exists, because the player has disconnected.

joserodpt commented 4 months ago

This should be solved in the latest commit and with the following .jar file: RealScoreboard.jar.zip

SlimeDog commented 4 months ago

Testing...

Quite a few issues:

I'm guessing that RSB has gone into an infinite thread creation loop.

SlimeDog commented 4 months ago

BTW, the builds listed in Github Actions have been failing to produce artifacts since last December.

joserodpt commented 4 months ago

Testing...

Quite a few issues:

  • Lines are not updating when I change worlds (title is correct, but no lines or lines from original world)
  • rsb debug displays correct information, except Config Version: 0 although config.yml shows Version: '16'
  • Server crashed due to out of memory pointing to the same Thread.java:1570 as above

I'm guessing that RSB has gone into an infinite thread creation loop.

So the previous version doesn't have those issues but still has the flicker?

joserodpt commented 4 months ago

BTW, the builds listed in Github Actions have been failing to produce artifacts since last December.

I know, I just don't have the time to fix it, my helper is going through with it

SlimeDog commented 4 months ago

So the previous version doesn't have those issues but still has the flicker?

Correct. Flicker on first join, and NPEs on disconnect.

joserodpt commented 4 months ago

Do you have any lead on what could be? Can't find the root cause of those issues

SlimeDog commented 4 months ago

No idea. But I cannot use RS in this condition. It crashes my server. What changed recently?

joserodpt commented 4 months ago

I tried to fix the flickering by checking if the current board was null, but that caused you server to crash as you said. Recently I changed the way the scoreboards load from the config, and added the other worlds list to every scoreboard

SlimeDog commented 3 months ago

It must come from my code on line 69

Agreed. Given

                        List<String> list = current.getLines().stream().map(s -> {
                            s = s.matches("(?i)%blank%") ?
                                    (Text.randomColor() + "§r" + Text.randomColor()) :
                                    RealScoreboardAPI.getInstance().getPlaceholders().setPlaceHolders(p, s);
                            return Text.color(s);
                        }).collect(Collectors.toList());
                        if (fastBoard != null && !fastBoard.isDeleted())
                            fastBoard.updateLines(list);

shouldn't the code verify that s is not null before using it, and that list is not null before using it?

joserodpt commented 2 months ago

Is this issue still active after the latest commit?

joserodpt commented 2 months ago

Can't get the server to throw an NPE when disconnecting with the latest commit

SlimeDog commented 2 months ago

Is there a build to test?

joserodpt commented 2 months ago

Sure! Here, compiled 12 minutes ago: RealScoreboard.jar.zip

SlimeDog commented 2 months ago

Paper 1.21-37 RealScoreboard 1.4.3

scoreboards.yml

Version: 3
Scoreboards:
  default:
    Default: true
    Default-World: world
    Other-Worlds:
    - '*'
    Display-Name: 'Admin Scoreboard'
    Permission: realscoreboard.admin
    Refresh:
      Scoreboard: 3
      Title: 20
      Title-Loop-Delay: 5
      Board-Loop-Delay: 20
    Boards:
      admin:
        Title:
        - '&7□□□□□□□□ &l%server_name%&r&7 □□□□□□□□'
        Lines:
        - '&8world:    &7%multiverse_world_alias%'
        - '&8location: &7%player_x% %player_y% %player_z%'
        - '&8chunk:    &7%coordinatetool_chunk%'
        - '&8region:   &7%coordinatetool_file%'
        - '&8b_biome:  &7%biomeremap_biome_name%'
        - '&8p_biome:  &7%player_biome%'
        - '&8time:     &7%player_world_time_24%'
        - '&8tps:      &7%server_tps_1% %server_tps_5%'
        - ''
        - '&8health:   &7%player_health%'
        - '&8deaths:   &7%statistic_deaths% (%plan_player_death_count%)'
        - '&8points$:  &7%vault_eco_balance%'
        - '&8group:    &7%luckperms_primary_group_name%'

When first connected, only the title appears. Eventually, the lines appear. When I change worlds, only the title appears. Eventually, the lines appear, but they are from the original world, not the current world. In addition, there are continuous console/log warnings as the player moves, which do not occur if RealScoreboard is not enabled:

[09:40:07 WARN]: Exception in thread "Craft Async Scheduler Management Thread" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
[09:40:07 WARN]:        at java.base/java.lang.Thread.start0(Native Method)
[09:40:07 WARN]:        at java.base/java.lang.Thread.start(Thread.java:1540)
[09:40:07 WARN]:        at java.base/java.lang.System$2.start(System.java:2582)
[09:40:07 WARN]:        at java.base/jdk.internal.vm.SharedThreadContainer.start(SharedThreadContainer.java:152)
[09:40:07 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:953)
[09:40:07 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1021)
[09:40:07 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1158)
[09:40:07 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[09:40:07 WARN]:        at java.base/java.lang.Thread.run(Thread.java:1570)
> [638.887s][warning][os,thread] Failed to start thread "Unknown thread" - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 4k, detached.
[638.890s][warning][os,thread] Failed to start the native thread for java.lang.Thread "Craft Scheduler Thread - 3982"
[638.890s][warning][os,thread] Failed to start thread "Unknown thread" - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 4k, detached.
[638.890s][warning][os,thread] Failed to start the native thread for java.lang.Thread "Craft Async Scheduler Management Thread"

and the server is basically dead-in-the-water.

joserodpt commented 2 months ago

With that config and the latest build I'm unable to reproduce that thread fail and the scoreboard behaviour that you're reporting. Tested on a simple server with 15 plugins.

SlimeDog commented 2 months ago

Simple Spigot or simple Paper. Version?

joserodpt commented 2 months ago

Paper version, 1.20.6 build

SlimeDog commented 2 months ago

The issue seems to be the %plan_player_death_count% placeholder. The scoreboard works fine without it, fails miserably with it.

joserodpt commented 2 months ago

That placeholder doesn't come from RSB, it's external. From which plugin is it? Does it run fine without that placeholder?

SlimeDog commented 2 months ago

RealScoreboard works fine without that (or any other Plan) placeholder. I opened an issue over there.

SlimeDog commented 2 months ago

Does RSB go into a loop if a placeholder (like any Plan placeholder) returns "%something%"?

joserodpt commented 2 months ago

Does RSB go into a loop if a placeholder (like any Plan placeholder) returns "%something%"?

In the RSB native placeholders i just do a replace, so i assume it doesnt, but i suppose that PAPI could enter a loop maybe?

SlimeDog commented 2 months ago

Just wondering, since a loop would explain the memory/CPU consumption.

SlimeDog commented 2 months ago

Are you going to publish RSB 1.4.3 ?

joserodpt commented 2 months ago

Yes, when i have time