Skip to content

Fix connection reset instead of kick message#595

Open
purpurcof wants to merge 1 commit into
jonesdevelopment:mainfrom
purpurcof:fix/connection-reset-verification
Open

Fix connection reset instead of kick message#595
purpurcof wants to merge 1 commit into
jonesdevelopment:mainfrom
purpurcof:fix/connection-reset-verification

Conversation

@purpurcof

@purpurcof purpurcof commented Jun 19, 2026

Copy link
Copy Markdown

Problem

After successful verification, the player receives "Connection Reset" instead of the proper kick/disconnect message.
Fixes #476

Root Cause

In VerificationHandler.fail(), after calling user.disconnect()closeWith(), a QuietDecoderException is thrown. The exception propagates to TailExceptionsHandler.exceptionCaught(), which calls ctx.close() immediately — before closeWith() can properly send the packet.

AbstractUnsafe.close() sets closeInitiated = true and nulls outboundBuffer, making the 50ms scheduled close from closeWith() a no-op. NioSocketChannel.doClose() calls javaChannel().close() right away. If the kernel receive buffer has unread data (a keep-alive from the client), the kernel sends TCP RST, discarding the pending disconnect data in the send buffer. The client sees "Connection Reset".

Fix

ProtocolUtil.closeWith()setAutoRead(false) + 50ms close delay:

  • setAutoRead(false) prevents client data from entering the kernel receive buffer
  • 50ms delay gives the TCP stack time to transmit the disconnect/transfer packet before close() is called

SonarPacketDecoder.channelRead() — catch QuietDecoderException:

  • The exception from fail() no longer reaches TailExceptionsHandler
  • closeInitiated is not set prematurely
  • closeWith() closes the channel after the delay as intended, not immediately

Made with Claude Opus 4.8

@lokspel

lokspel commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

#477

@jonesdevelopment jonesdevelopment self-assigned this Jun 19, 2026
@jonesdevelopment

Copy link
Copy Markdown
Owner

Please include the name and model of the AI you used to make this commit/PR.

@jonesdevelopment

Copy link
Copy Markdown
Owner

Were you able to reproduce #595 and test that this PR fixes it?

@purpurcof purpurcof force-pushed the fix/connection-reset-verification branch from 3ce7a5e to b0902a2 Compare June 20, 2026 16:35
@jonesdevelopment jonesdevelopment changed the title fix: connection reset instead of kick message Fix connection reset instead of kick message Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Connection reset instead of kick message

3 participants