SpigotMC / BungeeCord

BungeeCord, the 6th in a generation of server portal suites. Efficiently proxies and maintains connections and transport between multiple Minecraft servers.
https://www.spigotmc.org/go/bungeecord
Other
1.57k stars 1.11k forks source link

Sending plugin message to server on ServerSwitchEvent listener causes disconnect #3519

Closed Phoenix616 closed 1 year ago

Phoenix616 commented 1 year ago

Bungeecord version

git:BungeeCord-Bootstrap:1.20-R0.2-SNAPSHOT:f486a25:1737

Server version

3877-Spigot-17ca32d-f070277 (MC: 1.20.2)

Client version

1.20.2

Bungeecord plugins

BungeeResourcepacks

The bug

When switching servers you can get disconnected with several different errors. Some of those point to invalid packets in the CONFIGURATION phase (see the log for an error where this is pretty clear, there is also a similar but different error by a user of my plugin: https://hastebin.com/share/eqekunelay.css). The code point mentioned in this log is sending a plugin message with Server#sendData in a ServerSwitchListener.

This breaks how the API worked before and other things that could trigger packets to the server (or even client? seeing as the SystemChat packet is also mentioned in the error) in that phase might break too.

Possible solutions that I could think off:

Log output (links)

00:17:20 [SCHWERWIEGEND] [Phoenix616] <-> DownstreamBridge <-> [test] - encountered exception
io.netty.handler.codec.EncoderException: java.lang.IllegalArgumentException: Cannot get ID for packet class net.md_5.bungee.protocol.packet.PluginMessage in phase LOGIN with direction TO_SERVER
    at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:125)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:940)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:966)
    at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:934)
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1020)
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:311)
    at net.md_5.bungee.netty.ChannelWrapper.write(ChannelWrapper.java:85)
    at net.md_5.bungee.ServerConnection$1.sendPacket(ServerConnection.java:39)
    at net.md_5.bungee.ServerConnection.sendData(ServerConnection.java:46)
    at de.themoep.resourcepacksplugin.bungee.BungeeResourcepacks.sendPackInfo(BungeeResourcepacks.java:791)
    at de.themoep.resourcepacksplugin.bungee.listeners.ServerSwitchListener.onServerSwitch(ServerSwitchListener.java:49)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at net.md_5.bungee.event.EventHandlerMethod.invoke(EventHandlerMethod.java:19)
    at net.md_5.bungee.event.EventBus.post(EventBus.java:49)
    at net.md_5.bungee.api.plugin.PluginManager.callEvent(PluginManager.java:413)
    at net.md_5.bungee.ServerConnector.cutThrough(ServerConnector.java:370)
    at net.md_5.bungee.ServerConnector.handle(ServerConnector.java:153)
    at net.md_5.bungee.protocol.packet.LoginSuccess.handle(LoginSuccess.java:62)
    at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:124)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Cannot get ID for packet class net.md_5.bungee.protocol.packet.PluginMessage in phase LOGIN with direction TO_SERVER
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:463)
    at net.md_5.bungee.protocol.Protocol$DirectionData.getId(Protocol.java:813)
    at net.md_5.bungee.protocol.MinecraftEncoder.encode(MinecraftEncoder.java:25)
    at net.md_5.bungee.protocol.MinecraftEncoder.encode(MinecraftEncoder.java:10)
    at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
    ... 54 more
00:17:20 [SCHWERWIEGEND] [Phoenix616] -> UpstreamBridge - encountered exception
io.netty.handler.codec.EncoderException: java.lang.IllegalArgumentException: Cannot get ID for packet class net.md_5.bungee.protocol.packet.SystemChat in phase CONFIGURATION with direction TO_CLIENT
    at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:125)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:881)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:940)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:966)
    at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:934)
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1020)
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:311)
    at net.md_5.bungee.netty.ChannelWrapper.write(ChannelWrapper.java:85)
    at net.md_5.bungee.UserConnection$1.sendPacket(UserConnection.java:150)
    at net.md_5.bungee.UserConnection.sendMessage(UserConnection.java:492)
    at net.md_5.bungee.UserConnection.sendMessage(UserConnection.java:520)
    at net.md_5.bungee.UserConnection.sendMessage(UserConnection.java:461)
    at net.md_5.bungee.UserConnection.sendMessage(UserConnection.java:449)
    at net.md_5.bungee.UserConnection.sendMessage(UserConnection.java:434)
    at net.md_5.bungee.connection.DownstreamBridge.exception(DownstreamBridge.java:105)
    at net.md_5.bungee.netty.HandlerBoss.exceptionCaught(HandlerBoss.java:202)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:325)
    at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:317)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1377)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:346)
    at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:325)
    at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:907)
    at io.netty.channel.VoidChannelPromise.fireException0(VoidChannelPromise.java:236)
    at io.netty.channel.VoidChannelPromise.tryFailure(VoidChannelPromise.java:178)
    at io.netty.util.internal.PromiseNotificationUtil.tryFailure(PromiseNotificationUtil.java:64)
    at io.netty.channel.AbstractChannelHandlerContext.notifyOutboundHandlerException(AbstractChannelHandlerContext.java:990)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:884)
    at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:940)
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:966)
    at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:934)
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1020)
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:311)
    at net.md_5.bungee.netty.ChannelWrapper.write(ChannelWrapper.java:85)
    at net.md_5.bungee.ServerConnection$1.sendPacket(ServerConnection.java:39)
    at net.md_5.bungee.ServerConnection.sendData(ServerConnection.java:46)
    at de.themoep.resourcepacksplugin.bungee.BungeeResourcepacks.sendPackInfo(BungeeResourcepacks.java:791)
    at de.themoep.resourcepacksplugin.bungee.listeners.ServerSwitchListener.onServerSwitch(ServerSwitchListener.java:49)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at net.md_5.bungee.event.EventHandlerMethod.invoke(EventHandlerMethod.java:19)
    at net.md_5.bungee.event.EventBus.post(EventBus.java:49)
    at net.md_5.bungee.api.plugin.PluginManager.callEvent(PluginManager.java:413)
    at net.md_5.bungee.ServerConnector.cutThrough(ServerConnector.java:370)
    at net.md_5.bungee.ServerConnector.handle(ServerConnector.java:153)
    at net.md_5.bungee.protocol.packet.LoginSuccess.handle(LoginSuccess.java:62)
    at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:124)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: Cannot get ID for packet class net.md_5.bungee.protocol.packet.SystemChat in phase CONFIGURATION with direction TO_CLIENT
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:463)
    at net.md_5.bungee.protocol.Protocol$DirectionData.getId(Protocol.java:813)
    at net.md_5.bungee.protocol.MinecraftEncoder.encode(MinecraftEncoder.java:25)
    at net.md_5.bungee.protocol.MinecraftEncoder.encode(MinecraftEncoder.java:10)
    at io.netty.handler.codec.MessageToByteEncoder.write(MessageToByteEncoder.java:107)
    ... 80 more

Alternative error: https://hastebin.com/share/eqekunelay.css

Checking

Phoenix616 commented 1 year ago

What should I do if there is no API?

Propose API in form of an issue or even better PR ;)

NEZNAMY commented 1 year ago

Looking at the 110 open PRs and 256 issues I don't think it would do anything.

Phoenix616 commented 1 year ago

Looking at the 110 open PRs and 256 issues I don't think it would do anything.

I'm unsure what that has to do with anything. Issues that can be closed/resolved will be and PRs that are merge-able get merged. The amount of issues and PRs that aren't in such state is no indication for anything (beyond that a lot of people seem to not care enough to follow through with their stuff...)

md-5 commented 1 year ago

Looking at the 110 open PRs and 256 issues I don't think it would do anything.

Did you look at the 816 closed ones (88%)

Derbosik commented 1 year ago

Will the kicking get fixed? It doesn't seem like there's any way to even debug what plugin causes it and it needs a fix.

md-5 commented 1 year ago

Locking this ticket as the original issue has been resolved and subsequent comments appear to describing different issues with insufficient information which would be better suited to a new ticket complying with all requirements.