From 09c824ce6b5e5804987f6e0446802298a329462c Mon Sep 17 00:00:00 2001 From: HitPanda <104197232+EnefFlow@users.noreply.github.com> Date: Thu, 22 Jun 2023 01:35:48 +0300 Subject: [PATCH] Roundstart crash fix (#170) * [Fix] Possible fix for roundstart crash * Comments --- .../GameTicking/GameTicker.GamePreset.cs | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Content.Server/GameTicking/GameTicker.GamePreset.cs b/Content.Server/GameTicking/GameTicker.GamePreset.cs index a9d249a072..80d544d86c 100644 --- a/Content.Server/GameTicking/GameTicker.GamePreset.cs +++ b/Content.Server/GameTicking/GameTicker.GamePreset.cs @@ -1,5 +1,6 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Content.Server.GameTicking.Presets; using Content.Server.Maps; @@ -321,14 +322,32 @@ namespace Content.Server.GameTicking // TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN // Task.Run as a terrible dirty workaround to avoid synchronization context deadlock from .Result here. // This whole setup logic should be made asynchronous so we can properly wait on the DB AAAAAAAAAAAAAH + //WD start (HitPanda - Possibly fixed round start crashes here) + var mutex = new SemaphoreSlim(1, 1); + int result = default; + var task = Task.Run(async () => { var server = await _dbEntryManager.ServerEntity; - return await _db.AddNewRound(server, playerIds); + + await mutex.WaitAsync(); + + try + { + var round = await _db.AddNewRound(server, playerIds); + result = round; + } + finally + { + mutex.Release(); + } }); _taskManager.BlockWaitOnTask(task); - RoundId = task.GetAwaiter().GetResult(); + task.Wait(); + + RoundId = result; + //WD end } }