Repository navigation
Conversation
Contributor
[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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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