Skip to content

Keep listening when the server is full and skip slots being torn down - #284

Open
magaflaca wants to merge 1 commit into
Pryaxis:general-develfrom
magaflaca:fix/connection-accept-full-server
Open

magaflaca wants to merge 1 commit into
Pryaxis:general-develfrom
magaflaca:fix/connection-accept-full-server

Conversation

@magaflaca

Copy link
Copy Markdown

Problem

On TShock 6.x / Terraria 1.4.5, servers randomly stop accepting players: clients hang on "Connecting to IP:port" while the console keeps working normally. Only a restart fixes it.

Two issues in NetHooks.OnConnectionAccepted:

  1. The listener is stopped and never restarted. When the accepted client takes the last free slot, Netplay.TcpListener.StopListening() is called. Terraria 1.4.4 restarted the listener from the server loop once a slot freed up, but 1.4.5 removed that code path (vanilla 1.4.5 never stops listening; it kicks with CLI.ServerIsFull instead). Result: once the server is full a single time, the port is closed until restart, even after everyone leaves.
  2. Slots that are still being torn down are reused. FindNextOpenClientSlot only checks !IsConnected(). A slot whose previous socket is already closed but which is still IsActive / PendingTermination is handed to the new client, and UpdateConnectedClients then calls Reset() on it, dropping the new connection. This is why quick reconnects often fail.

Seems like Pryaxis/TShock#3321

Fix

  • When no slot is free, reject with the vanilla CLI.ServerIsFull message through Netplay.KickClient (same lock as vanilla), close that socket, and keep listening.
  • Only consider a slot free when it is not connected, not active and not pending termination.

Pairs with Pryaxis/TShock#3325 (LinuxTcpSocket dead-client detection), which frees the slots that would otherwise keep the server full.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant