Repository navigation
Conversation
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
On TShock 6.2.1 / Terraria 1.4.5.8 a server can hang right after a player disconnects: the console stops (TShock then reports "Unable to write to log as log has been disposed"), the port stays open and accepts connections, but nobody is served. The process never exits, so restart loops and service managers don't restart it.
Two issues combine:
NetMessage.LogMessageErrorthrows. Terraria 1.4.5.8 added this method andCheckBytescalls it whenGetDatathrows. It builds the message withNetplay.Clients[bufferIndex].Socket.GetRemoteAddress()without a null check. If the slot's client already disconnected (RemoteClient.Reset()setSocket = null) while one of its packets was still being processed, a harmless packet error becomes aNullReferenceExceptionthat escapesCheckBytesand ends the main game loop. Terraria 1.4.4.9 and 1.4.5.6 only wrote the error to the console here, without touching the socket.Program.RunGamecatches the exception and returns, and TSAPI unloads the plugins, butNetplay.Disconnectis never set.Netplay.ServerLoopkeeps running and the foregroundBroadcastThreadkeeps the process alive indefinitely.Production stack trace:
Issue: Pryaxis/TShock#3324
Fix
NetMessage.LogMessageErrorand log the same message throughInvariant.Assert, usingSocket?.GetRemoteAddress().Netplay.Disconnect = trueonceWindowsLaunch.Mainreturns, so the network threads stop and the process exits after an abnormal end of the game loop. A normal shutdown already sets it, so nothing changes there.Changelog
LogMessageErrorthrew on the missing socket and ended the game loop.