mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-13 09:03:15 +01:00
Clean up race condition in BridgeController content logging disabling
This commit is contained in:
@@ -36,7 +36,12 @@ namespace Tgstation.Server.Host.Controllers
|
||||
/// <summary>
|
||||
/// If the content of bridge requests and responses should be logged.
|
||||
/// </summary>
|
||||
internal static bool LogContent { get; set; }
|
||||
static bool LogContent => logContentDisableCounter == 0;
|
||||
|
||||
/// <summary>
|
||||
/// Counter which, if not zero, indicates content logging should be disabled.
|
||||
/// </summary>
|
||||
static uint logContentDisableCounter;
|
||||
|
||||
/// <summary>
|
||||
/// Static counter for the number of requests processed.
|
||||
@@ -54,12 +59,14 @@ namespace Tgstation.Server.Host.Controllers
|
||||
readonly ILogger<BridgeController> logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static members of the <see cref="BridgeController"/> class.
|
||||
/// Temporarily disable content logging. Must be followed up with a call to <see cref="ReenableContentLogging"/>.
|
||||
/// </summary>
|
||||
static BridgeController()
|
||||
{
|
||||
LogContent = true;
|
||||
}
|
||||
internal static void TemporarilyDisableContentLogging() => Interlocked.Increment(ref logContentDisableCounter);
|
||||
|
||||
/// <summary>
|
||||
/// Reenable content logging. Must be preceeded with a call to <see cref="TemporarilyDisableContentLogging"/>.
|
||||
/// </summary>
|
||||
internal static void ReenableContentLogging() => Interlocked.Decrement(ref logContentDisableCounter);
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BridgeController"/> class.
|
||||
|
||||
@@ -893,7 +893,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
{
|
||||
// first check the bridge limits
|
||||
var bridgeTestsTcs = new TaskCompletionSource();
|
||||
BridgeController.LogContent = false;
|
||||
BridgeController.TemporarilyDisableContentLogging();
|
||||
using (var loggerFactory = LoggerFactory.Create(builder =>
|
||||
{
|
||||
builder.AddConsole();
|
||||
@@ -914,7 +914,7 @@ namespace Tgstation.Server.Tests.Live.Instance
|
||||
await bridgeTestsTcs.Task.WaitAsync(cancellationToken);
|
||||
}
|
||||
|
||||
BridgeController.LogContent = true;
|
||||
BridgeController.ReenableContentLogging();
|
||||
|
||||
// Time for DD to revert the bridge access identifier change
|
||||
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user