Fix startround deadlock (#11498)
This commit is contained in:
@@ -19,11 +19,14 @@ using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Robust.Shared.Asynchronous;
|
||||
|
||||
namespace Content.Server.GameTicking
|
||||
{
|
||||
public sealed partial class GameTicker
|
||||
{
|
||||
[Dependency] private readonly ITaskManager _taskManager = default!;
|
||||
|
||||
private static readonly Counter RoundNumberMetric = Metrics.CreateCounter(
|
||||
"ss14_round_number",
|
||||
"Round number.");
|
||||
@@ -152,16 +155,18 @@ namespace Content.Server.GameTicking
|
||||
|
||||
var playerIds = _playerGameStatuses.Keys.Select(player => player.UserId).ToArray();
|
||||
var serverName = _configurationManager.GetCVar(CCVars.AdminLogsServerName);
|
||||
|
||||
// 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
|
||||
#pragma warning disable RA0004
|
||||
RoundId = Task.Run(async () =>
|
||||
var task = Task.Run(async () =>
|
||||
{
|
||||
var server = await _db.AddOrGetServer(serverName);
|
||||
return await _db.AddNewRound(server, playerIds);
|
||||
}).Result;
|
||||
#pragma warning restore RA0004
|
||||
});
|
||||
|
||||
_taskManager.BlockWaitOnTask(task);
|
||||
RoundId = task.GetAwaiter().GetResult();
|
||||
|
||||
var startingEvent = new RoundStartingEvent(RoundId);
|
||||
RaiseLocalEvent(startingEvent);
|
||||
|
||||
Reference in New Issue
Block a user