SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
83 stars 17 forks source link

Server freezing when a player joins the server. #4418

Closed EmersonCamy closed 3 weeks ago

EmersonCamy commented 1 month ago

I've seen this error occur once in 2018 when a server received a lot of tcp connections, it was something related to steam that was fixed.

But today it happened to me again, some players are playing and when one tries to join the server freezes, when the player finishes loading, the server comes back again and kicks out all the other players.

logs: [04/06/2024 23:47:44] [Info] filho do caetano [PedroThiagoDz] bled to death! [04/06/2024 23:47:44] [Info] uPanel >> [uPanel] Auto Saved Server! [04/06/2024 23:48:11] [Info] Connecting: PlayerID: 76561199415617646 Name: zCrazyMonkeyz Character: Wonder of U [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561199436472098 Name: El Pache Character: El Escurridiso Jhonsonn [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561198233764444 Name: xipan Character: tensinera [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561198979702090 Name: ঔ☬✞SHADOW✞☬ঔ Character: SHADOW [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561198883176582 Name: AHAN CAXOTA Character: AHAN CAXOTA [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561198263665640 Name: Mano_Gui Character: Mano_Gui [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561199572090255 Name: FBI Character: :( [04/06/2024 23:49:53] [Info] Disconnecting: PlayerID: 76561199479110107 Name: PedroThiagoDz Character: filho do caetano [04/06/2024 23:49:53] [Info] Player finished session: 76561199436472098 [04/06/2024 23:49:53] [Info] Player finished session: 76561198883176582 [04/06/2024 23:49:53] [Info] Player finished session: 76561198233764444 [04/06/2024 23:49:53] [Info] Player finished session: 76561198979702090 [04/06/2024 23:49:53] [Info] Player finished session: 76561199572090255 [04/06/2024 23:49:53] [Info] Player finished session: 76561199634324135 [04/06/2024 23:49:53] [Info] Player finished session: 76561198263665640 [04/06/2024 23:49:53] [Info] Player finished session: 76561199479110107 [04/06/2024 23:49:53] [Info] Player finished session: 76561199415617646

SDGNelson commented 1 month ago

Sorry about that. Can you attach your server's log file, please? (the text in the original post looks like maybe Rocket's log, not the game's log file) https://support.smartlydressedgames.com/hc/en-us/articles/12298951221908-Where-are-the-dedicated-server-log-files

warren39 commented 1 month ago

This might help you, Some laptops or graphics cards come with additional optimization programs that claim to be optimized for UDP. Unfortunately, it breaks communication between Unturned users and the server. Eventually, the server seems to stop and wait for player data until it times out. This caused all players in the server to go offline. The solution is for players to disable these UDP optimizers. This happened a few years ago, but I haven't encountered it recently.

DanielWillett commented 1 month ago

I've also seen errors like this from plugins using the UnturnedPlayer.SteamProfile property in LDM, which performs a full web request on the main thread with a pretty long timeout. Sometimes steam just doesn't respond causing everyone to get timed out with no clear cause. This is probably better suited for the LDM repo but it would be great if you could add like a 2 second timeout to that web request in https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/blob/master/Rocket/Rocket.Core/Steam/Profile.cs. There's some ways to add timeouts to WebClients in this thread https://stackoverflow.com/questions/1789627/how-to-change-the-timeout-on-a-net-webclient-object.

Better solution would probably be to just use a UnityWebRequest with a timeout and a while !isDone Thread.sleep(50) waiting for it to finish and to obsolete that property since no one should be running web requests on the main thread in the first place. Instead an async method could be added:

/* UnturnedPlayer */

[Obsolete("Use GetSteamProfile() instead")]
// maybe caching this for a certain amount of time wouldn't hurt.
public Profile SteamProfile => new Profile(CSteamID.m_SteamID);

public Task<Profile> GetSteamProfileAsync()
{
   return Profile.CreateAsync(CSteamID.m_SteamID);
}

/* Profile */
[Obsolete("Use CreateAsync() instead")]
public void Reload()
{
    XmlDocument doc = new XmlDocument();
    string url = "http://steamcommunity.com/profiles/" + SteamID64 + "?xml=1";
    if (ThreadUtil.gameThread == Thread.CurrentThread)
    {
        using UnityWebRequest request = UnityWebRequest.Get(url);
        request.timeout = 2f;

        UnityWebRequestAsyncOperation operation = request.SendWebRequest();

        while (!operation.isDone)
            Thread.Sleep(15);

        if (request.result != UnityWebRequest.Result.Success) // retry maybe
            throw new Exception($"Failed to fetch steam profile for {SteamID64} - {request.responseCode} - \"{request.error}\".");

        doc.LoadXml(request.downloadHandler.text);
    }
    else
    {
        // use web client like before but Dispose it
    }

    // move parse code to FromXml
    this.FromXml(doc);
}

private Profile() { }

/* Profile.CreateAsync() */
public async Task<Profile> CreateAsync(CSteamID steamId)
{
   using WebClient client = new WebClient();
   string xmlData = await client.DownloadStringAsync("http://steamcommunity.com/profiles/" + SteamID64 + "?xml=1");
   XmlDocument doc = new XmlDocument();
   doc.LoadXml(xmlData);

   Profile profile = new Profile
   {
       SteamID64 = steamId.m_SteamID
   };
   profile.FromXml(doc);
   return profile;
}
SDGNelson commented 3 weeks ago

Closing for now but feel free to comment and I'll re-open.