retrooper / packetevents

Precision meets performance—a powerful tool for mastering Minecraft packet manipulation with speed and finesse.
GNU General Public License v3.0
555 stars 150 forks source link

Race condition when sending same packet concurrently #991

Closed DevDrizzy closed 2 months ago

DevDrizzy commented 2 months ago

Describe the bug I am re-using your team creation packet wrapper, and it may be sent more than once, concurrently packetevents apparently doesnt acount for race conditions here properly, thus throwing an NPE

Software brand PaperSpigot 1.8.8

Plugins Apollo-Bukkit, FAWE, PAPI, VoidWorld, ProtocolLib, MVU, ServerNPC, WorldEdit, Citizens, spark, DecentHolograms, Retention, Phoenix, Bolt, pxStaff, pxBasic, pxQueue

How To Reproduce Steps to reproduce the behavior:

  1. Cache a Packet Wrapper on join for one player.
  2. Send the same Packet Wrapper on join for other players
  3. Have multiple people join the server at once,

Expected behavior The packet is sent normally without null pointer exceptions.

Screenshots

[14:50:09 INFO]: UUID of player NotDrizzy is 1634ecf3-22a3-4c1b-8fa0-580ae7aed8a4
[14:50:09 INFO]: Bermine[hidden-address:44822] logged in with entity id 194 at ([world]-592.5, 96.0, 77.5)
[14:50:09 INFO]: NotDrizzy[hidden-address:44830] logged in with entity id 195 at ([world]-592.5, 96.0, 77.5)
[14:50:09 WARN]: Exception in thread "Craft Scheduler Thread - 35" org.apache.commons.lang.UnhandledException: Plugin Bolt v1.2 generated an exception while executing task 19817
[14:50:09 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(Carbon:57)
[14:50:09 WARN]:        at org.github.paperspigot.ServerSchedulerReportingWrapper.run(Carbon:23)
[14:50:09 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
[14:50:09 WARN]:        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
[14:50:09 WARN]:        at java.base/java.lang.Thread.run(Thread.java:1583)
[14:50:09 WARN]: Caused by: java.lang.NullPointerException: msg
[14:50:09 WARN]:        at io.netty.util.internal.ObjectUtil.checkNotNull(ObjectUtil.java:39)
[14:50:09 WARN]:        at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025)
[14:50:09 WARN]:        at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:306)
[14:50:09 WARN]:        at xyz.refinedev.libs.io.github.retrooper.packetevents.netty.channel.ChannelOperatorModernImpl.writeAndFlush(ChannelOperatorModernImpl.java:60)
[14:50:09 WARN]:        at xyz.refinedev.libs.com.github.retrooper.packetevents.netty.channel.ChannelHelper.writeAndFlush(ChannelHelper.java:53)
[14:50:09 WARN]:        at xyz.refinedev.libs.io.github.retrooper.packetevents.manager.protocol.ProtocolManagerImpl.sendPacket(ProtocolManagerImpl.java:56)
[14:50:09 WARN]:        at xyz.refinedev.libs.com.github.retrooper.packetevents.manager.protocol.ProtocolManager.sendPackets(ProtocolManager.java:61)
[14:50:09 WARN]:        at xyz.refinedev.libs.com.github.retrooper.packetevents.manager.protocol.ProtocolManager.sendPacket(ProtocolManager.java:117)
[14:50:09 WARN]:        at xyz.refinedev.libs.com.github.retrooper.packetevents.manager.player.PlayerManager.sendPacket(PlayerManager.java:45)
[14:50:09 WARN]:        at xyz.refinedev.api.practice.nametag.util.packet.PacketUtil.sendPacket(PacketUtil.java:36)
[14:50:09 WARN]:        at xyz.refinedev.api.practice.nametag.NameTagHandler.initiatePlayer(NameTagHandler.java:164)
[14:50:09 WARN]:        at xyz.refinedev.api.practice.nametag.listener.NameTagListener.lambda$onPlayerJoin$0(NameTagListener.java:43)
[14:50:09 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(Carbon:64)
[14:50:09 WARN]:        at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(Carbon:53)
[14:50:09 WARN]:        ... 4 more

Additional context For my issue, I was using my NameTagAPI made using PacketEvents, which caches team creation packets when a team is prompted to be created, and then sends the same packet for any other player joining to have the team created for them. Can be seen here