Repository navigation
Conversation
[Medium impact] The change affects client connections handled by Linux server sockets. The PR appears safe to merge, with a non-blocking improvement to keep rejected keepalive settings from silently blocking joins. Findings
SummaryThis PR helps
One non-blocking improvement remains: rejected keepalive settings should not silently prevent players from joining. Reviews (1) · Last reviewed commit: "Detect dead and half-closed clients in L..." · Reviewed by Greptile |
|
Independent test result: #3325 fixes the slot leak from connect-and-close probes (0 |
Problem
Clients that disappear without a clean disconnect keep their slot forever. This happens on mobile all the time (lost signal, app killed, network switch). With enough of them the server fills up with ghosts and nobody can join; together with the listener bug fixed in NyxStudios/TerrariaAPI-Server#, the port then closes for good.
Three causes in
LinuxTcpSocket:IsDataAvailablereturnsNetworkStream.DataAvailable.RemoteClient.TryReadonly starts a read when this is true, so the read that would return 0 bytes on FIN (or fail on a socket error) is never issued, and Terraria never notices the disconnect.IsConnected(TcpClient.Connected) also stays true, because nothing failed yet.ReadCallbackcloses the socket onInvalidOperationException, but anIOException(connection reset / timed out) is only logged. The read callback is never invoked, and the slot stays occupied.It´s this issue #3321
Fix
IsDataAvailableusesSocket.Poll(0, SelectMode.SelectRead), which is true for pending data, FIN and errors. Terraria then runs its normal read path: 0 bytes →PendingTermination.IOExceptioninReadCallbacklikeInvalidOperationExceptionand close the socket.Connected players are unaffected: they send data constantly, and keepalive probes are answered by the client OS.
Changelog