Repository navigation
Keep listening when the server is full and skip slots being torn down - #284
Conversation
|
Tested this together with Pryaxis/TShock#3325 on TShock 6.2.1 (base
I also checked the root cause by decompiling One note in case it helps: I first tried the same change without Minor observation: with #284, in a second "fill all 8 slots" round right after a previous one, the 9th connection sometimes got a slot. I believe that's the intended "skip slots being torn down" behaviour (one of the 8 held sockets was rejected while a slot was still pending termination), not a bug. So from my side: #3325 + #284 together fix #3321. Either one alone does not. |
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: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 withCLI.ServerIsFullinstead). Result: once the server is full a single time, the port is closed until restart, even after everyone leaves.FindNextOpenClientSlotonly checks!IsConnected(). A slot whose previous socket is already closed but which is stillIsActive/PendingTerminationis handed to the new client, andUpdateConnectedClientsthen callsReset()on it, dropping the new connection. This is why quick reconnects often fail.Seems like Pryaxis/TShock#3321
Fix
CLI.ServerIsFullmessage throughNetplay.KickClient(same lock as vanilla), close that socket, and keep listening.Pairs with Pryaxis/TShock#3325 (LinuxTcpSocket dead-client detection), which frees the slots that would otherwise keep the server full.