ProtocolLib

3M Downloads

Allow changing thread name of Async Protocol Workers

diogotcorreia opened this issue ยท 2 comments

commented
  • This feature is not currently present in a development build

Is your feature request related to a problem? Please describe.
I have an async packet listener with a very big whitelist. This causes the following log messages due to the thread name:

[17:02:54] [Protocol Worker #1 - Triton - [recv: SETTINGS[class=PacketPlayInSettings, id=7], send: WINDOW_ITEMS[class=PacketPlayOutWindowItems, id=17], SCOREBOARD_OBJECTIVE[class=PacketPlayOutScoreboardObjective, id=83], SET_SLOT[class=PacketPlayOutSetSlot, id=19], SCOREBOARD_TEAM[class=PacketPlayOutScoreboardTeam, id=85], SET_SUBTITLE_TEXT[class=ClientboundSetSubtitleTextPacket, id=88], SET_TITLE_TEXT[class=ClientboundSetTitleTextPacket, id=90], SET_ACTION_BAR_TEXT[class=ClientboundSetActionBarTextPacket, id=64], PLAYER_LIST_HEADER_FOOTER[class=PacketPlayOutPlayerListHeaderFooter, id=96], SYSTEM_CHAT[class=ClientboundSystemChatPacket, id=95], MAP_CHUNK[class=ClientboundLevelChunkWithLightPacket, id=31], ADVANCEMENTS[class=PacketPlayOutAdvancements, id=100], OPEN_WINDOW_MERCHANT[class=PacketPlayOutOpenWindowMerchant, id=37], TILE_ENTITY_DATA[class=PacketPlayOutTileEntityData, id=7], BOSS[class=PacketPlayOutBoss, id=10], OPEN_WINDOW[class=PacketPlayOutOpenWindow, id=43]]/INFO]: [Triton] [TRACE] Found translation with key 'tab.test.footer' in language 'en_GB'

As you can see, it's a pretty huge thread name, rendering the log pretty useless.
Keep in mind that this mostly happens on vanilla Spigot, since Paper and other forks don't show up the thread name on logs.

Describe the solution you'd like
There should be a way to override the default thread name. Either setting the name directly, or overriding the getFriendlyWorkerName method.

public String getFriendlyWorkerName(int id) {

Describe alternatives you've considered
A workaround I've found is to create an AtomicBoolean to save the first time the listener is called and set the thread name there:

    private final AtomicBoolean firstRun = new AtomicBoolean(true);

    @Override
    public void onPacketSending(PacketEvent packet) {
        if (firstRun.compareAndSet(true, false) && !Bukkit.getServer().isPrimaryThread()) {
            Thread.currentThread().setName("Triton Async Packet Handler");
        }
        
        // ...
    }

Additional context
The console log is basically unreadable:
image

commented

Yea we can change that for sure. The current plan is to clean up everything in v5 and that part isn't touched yet (everything is a bit stale as we were expecting 1.19.1 to release, but it didn't ๐Ÿ˜‚)

commented

Please reopen since it's still a desirable feature :)