MCProtocolLib
MCProtocolLib copied to clipboard
nioEventLoopGroup thread prevents JVM from exiting
Hi, I had a similar problem with #408 with both 1.18.2-1 and 1.18.2-2-SNAPSHOT. Not sure what I did wrong but here is what happened:
The dependencies in my build.gradle
:
implementation("com.github.GeyserMC:opennbt:1.4")
implementation("com.github.steveice10:packetlib:2.1")
implementation("com.github.GeyserMC:mcauthlib:6f3d6aada5")
implementation("com.github.steveice10:mcprotocollib:1.18.2-1") // Same with 1.18.2-2-SNAPSHOT
Code snippet:
val threadsBefore = Thread.getAllStackTraces().keys
val protocol = MinecraftProtocol("whosyourdaddy")
val sessionService = SessionService()
val client = TcpClientSession("localhost", 25565, protocol, null)
client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService)
client.addListener(object: SessionAdapter() {
override fun packetReceived(session: Session, packet: Packet) {
if (packet is ClientboundLoginPacket) {
session.send(ServerboundChatPacket("Dummy client connected!"))
} else if (packet is ClientboundChatPacket) {
println("Received chat message: ${packet.message}")
println("Session alive: ${session.isConnected}")
session.disconnect("Done")
}
}
override fun disconnected(event: DisconnectedEvent) {
println("Client disconnected: ${event.reason}")
event.cause?.printStackTrace()
}
})
client.connect()
delay(2000)
val threadsAfter = Thread.getAllStackTraces().keys
delay(1000)
println(threadsAfter.subtract(threadsBefore))
And the output:
Received chat message: TranslatableComponentImpl{key="multiplayer.player.joined", args=[TextComponentImpl{content="whosyourdaddy", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=ClickEvent{action=suggest_command, value="/tell whosyourdaddy "}, hoverEvent=HoverEvent{action=show_entity, value=ShowEntity{type=KeyImpl{namespace="minecraft", value="player"}, id=91c854ef-9614-3273-bf16-73b2960d59ac, name=TextComponentImpl{content="whosyourdaddy", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}}}, insertion="whosyourdaddy", font=null}, children=[]}], style=StyleImpl{color=NamedTextColor{name="yellow", value="#ffff55"}, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
Session alive: true
Received chat message: TranslatableComponentImpl{key="chat.type.text", args=[TextComponentImpl{content="whosyourdaddy", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}, TextComponentImpl{content="Dummy client connected!", style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}], style=StyleImpl{color=null, obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
Session alive: false
Client disconnected: Done
[Thread[DefaultDispatcher-worker-6,5,main], Thread[DefaultDispatcher-worker-7,5,main], Thread[nioEventLoopGroup-3-1,10,main], Thread[defaultEventLoopGroup-2-1,10,main]]
Note the extra NIO thread in the end which prevents JVM from exiting.