Fix concurrent access issues with ConnectedClients
Replaced direct access to GameMain.Server.ConnectedClients with array snapshots in multiple server-side classes to prevent concurrent modification issues during parallel updates. Also updated PhysicsBody and LevelTrigger to avoid static/shared state in parallel contexts, improving thread safety and reliability.
This commit is contained in:
@@ -4799,7 +4799,9 @@ namespace Barotrauma.Networking
|
||||
public static string CharacterLogName(Character character)
|
||||
{
|
||||
if (character == null) { return "[NULL]"; }
|
||||
Client client = GameMain.Server.ConnectedClients.Find(c => c.Character == character);
|
||||
// Create snapshot to avoid concurrent access issues during parallel updates
|
||||
var clients = GameMain.Server.ConnectedClients.ToArray();
|
||||
Client client = clients.FirstOrDefault(c => c.Character == character);
|
||||
return ClientLogName(client, character.LogName);
|
||||
}
|
||||
|
||||
@@ -4810,8 +4812,8 @@ namespace Barotrauma.Networking
|
||||
GameMain.LuaCs?.Hook?.Call("serverLog", line, messageType);
|
||||
|
||||
GameMain.Server.ServerSettings.ServerLog.WriteLine(line, messageType);
|
||||
|
||||
foreach (Client client in GameMain.Server.ConnectedClients)
|
||||
var clients = GameMain.Server.ConnectedClients.ToArray();
|
||||
foreach (Client client in clients)
|
||||
{
|
||||
if (!client.HasPermission(ClientPermissions.ServerLog)) continue;
|
||||
//use sendername as the message type
|
||||
|
||||
Reference in New Issue
Block a user