Roundstart crash fix (#170)

* [Fix] Possible fix for roundstart crash

* Comments
This commit is contained in:
HitPanda
2023-06-22 01:35:48 +03:00
committed by Aviu00
parent d3417bb6d0
commit 09c824ce6b

View File

@@ -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
}
}