Roundstart crash fix (#170)
* [Fix] Possible fix for roundstart crash * Comments
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Content.Server.GameTicking.Presets;
|
using Content.Server.GameTicking.Presets;
|
||||||
using Content.Server.Maps;
|
using Content.Server.Maps;
|
||||||
@@ -321,14 +322,32 @@ namespace Content.Server.GameTicking
|
|||||||
// TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN
|
// TODO FIXME AAAAAAAAAAAAAAAAAAAH THIS IS BROKEN
|
||||||
// Task.Run as a terrible dirty workaround to avoid synchronization context deadlock from .Result here.
|
// 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
|
// 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 task = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var server = await _dbEntryManager.ServerEntity;
|
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);
|
_taskManager.BlockWaitOnTask(task);
|
||||||
RoundId = task.GetAwaiter().GetResult();
|
task.Wait();
|
||||||
|
|
||||||
|
RoundId = result;
|
||||||
|
//WD end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user