Merge branch 'master' into FixPRCodeQL

This commit is contained in:
Jordan Dominion
2023-06-07 08:04:38 -04:00
committed by GitHub
11 changed files with 51 additions and 29 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ jobs:
doxyfile-path: 'docs/Doxyfile'
- name: gh-pages push
if: github.event_name == 'push' && github.event.ref == 'refs/heads/dev'
if: github.event_name == 'push' && github.event.ref == 'refs/heads/dev' && env.TGS_RELEASE_NOTES_TOKEN != ''
run: |
git clone -b gh-pages --single-branch "https://git@github.com/tgstation/tgstation-server" $HOME/tgsdox
pushd $HOME/tgsdox
+1 -1
View File
@@ -16,6 +16,6 @@ Vulnerabilities should ideally be reported by directly messaging one of the TGS
Here is a list of their discord IDs.
@Cyberboss - Dominion#0444 (<@133295178197893120>)
@Cyberboss - dominion (<@133295178197893120>)
Once reported, they will handle the processing of the security advisory.
@@ -309,7 +309,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers
cancellationToken);
// DCT: Always wait for the job to complete here
await jobManager.WaitForJobCompletion(job, null, cancellationToken, default);
await jobManager.WaitForJobCompletion(job, null, cancellationToken, cancellationToken);
}
}
catch (OperationCanceledException e)
@@ -514,11 +514,9 @@ namespace Tgstation.Server.Host.Components
await jobManager.RegisterOperation(
repositoryUpdateJob,
RepositoryAutoUpdateJob,
cancellationToken)
;
cancellationToken);
// DCT: First token will cancel the job, second is for cancelling the cancellation, unwanted
await jobManager.WaitForJobCompletion(repositoryUpdateJob, null, cancellationToken, default);
await jobManager.WaitForJobCompletion(repositoryUpdateJob, null, cancellationToken, cancellationToken);
Job compileProcessJob;
using (var repo = await RepositoryManager.LoadRepository(cancellationToken))
@@ -854,7 +854,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
var heartbeatSeconds = ActiveLaunchParameters.HeartbeatSeconds.Value;
var heartbeat = heartbeatSeconds == 0
|| !controller.DMApiAvailable
? Extensions.TaskExtensions.InfiniteTask()
? Extensions.TaskExtensions.InfiniteTask
: Task.Delay(
TimeSpan.FromSeconds(heartbeatSeconds),
cancellationToken);
@@ -14,6 +14,11 @@ namespace Tgstation.Server.Host.Extensions
/// </summary>
static readonly TaskCompletionSource InfiniteTaskCompletionSource = new ();
/// <summary>
/// Gets a <see cref="Task"/> that never completes.
/// </summary>
public static Task InfiniteTask => InfiniteTaskCompletionSource.Task;
/// <summary>
/// Create a <see cref="Task"/> that can be awaited while respecting a given <paramref name="cancellationToken"/>.
/// </summary>
@@ -53,11 +58,5 @@ namespace Tgstation.Server.Host.Extensions
return await task;
}
/// <summary>
/// Creates a <see cref="Task"/> that never completes.
/// </summary>
/// <returns>A never ending <see cref="Task"/>.</returns>
public static Task InfiniteTask() => InfiniteTaskCompletionSource.Task;
}
}
+15 -10
View File
@@ -11,6 +11,21 @@ namespace Tgstation.Server.Host.Jobs
/// </summary>
sealed class JobHandler : IDisposable
{
/// <summary>
/// If the job has started.
/// </summary>
public bool Started => task != null;
/// <summary>
/// The progress of the job.
/// </summary>
public int? Progress { get; set; }
/// <summary>
/// The stage of the job.
/// </summary>
public string Stage { get; set; }
/// <summary>
/// The <see cref="CancellationTokenSource"/> for <see cref="task"/>.
/// </summary>
@@ -39,16 +54,6 @@ namespace Tgstation.Server.Host.Jobs
/// <inheritdoc />
public void Dispose() => cancellationTokenSource.Dispose();
/// <summary>
/// The progress of the job.
/// </summary>
public int? Progress { get; set; }
/// <summary>
/// The stage of the job.
/// </summary>
public string Stage { get; set; }
/// <summary>
/// Wait for <see cref="task"/> to complete.
/// </summary>
@@ -256,13 +256,23 @@ namespace Tgstation.Server.Host.Jobs
{
if (job == null)
throw new ArgumentNullException(nameof(job));
if (!cancellationToken.CanBeCanceled)
throw new ArgumentException("A cancellable CancellationToken should be provided!", nameof(cancellationToken));
JobHandler handler;
bool noMoreJobsShouldStart;
lock (synchronizationLock)
{
if (!jobs.TryGetValue(job.Id.Value, out handler))
return;
noMoreJobsShouldStart = this.noMoreJobsShouldStart;
}
if (noMoreJobsShouldStart && !handler.Started)
await Extensions.TaskExtensions.InfiniteTask.WithToken(cancellationToken);
Task cancelTask = null;
using (jobCancellationToken.Register(() => cancelTask = CancelJob(job, canceller, true, cancellationToken)))
await handler.Wait(cancellationToken);
@@ -380,7 +380,7 @@ namespace Tgstation.Server.Host.Swarm
? asyncDelayer.Delay(
TimeSpan.FromMinutes(UpdateCommitTimeoutMinutes),
cancellationToken)
: Extensions.TaskExtensions.InfiniteTask().WithToken(cancellationToken);
: Extensions.TaskExtensions.InfiniteTask.WithToken(cancellationToken);
var commitTask = Task.WhenAny(commitTcsTask, timeoutTask);
@@ -59,8 +59,8 @@ namespace Tgstation.Server.Tests.Live.Instance
if (!targetActiveJob.Progress.HasValue)
{
// give it 15 more seconds
targetActiveJob = await WaitForJobProgress(targetActiveJob, 15, cancellationToken);
// give it a few more seconds
targetActiveJob = await WaitForJobProgress(targetActiveJob, 30, cancellationToken);
allJobs = await JobsClient.List(null, cancellationToken);
}
@@ -246,7 +246,14 @@ namespace Tgstation.Server.Tests.Live.Instance
jobTcs.SetResult();
await killTask;
}
Assert.IsTrue(job.ErrorCode == ErrorCode.DreamDaemonOffline || job.ErrorCode == ErrorCode.GCoreFailure, $"{job.ErrorCode}: {job.ExceptionDetails}");
// these can also happen
if (!(new PlatformIdentifier().IsWindows
&& (job.ExceptionDetails.Contains("BetterWin32Errors.Win32Exception: E_ACCESSDENIED: Access is denied.")
|| job.ExceptionDetails.Contains("BetterWin32Errors.Win32Exception: E_HANDLE: The handle is invalid.")
|| job.ExceptionDetails.Contains("BetterWin32Errors.Win32Exception: 3489660936: Unknown error (0xd0000008)")))) // kek
Assert.IsTrue(job.ErrorCode == ErrorCode.DreamDaemonOffline || job.ErrorCode == ErrorCode.GCoreFailure, $"{job.ErrorCode}: {job.ExceptionDetails}");
await Task.Delay(TimeSpan.FromSeconds(20), cancellationToken);
var ddStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
@@ -531,7 +538,7 @@ namespace Tgstation.Server.Tests.Live.Instance
TopicResponse topicRequestResult = null;
try
{
System.Console.WriteLine($"Topic limit test S:{payloadSize}...");
System.Console.WriteLine($"Topic send limit test S:{currentSize}...");
topicRequestResult = await TopicClientNoLogger.SendTopic(
IPAddress.Loopback,
$"tgs_integration_test_tactics3={TopicClient.SanitizeString(JsonConvert.SerializeObject(topic, DMApiConstants.SerializerSettings))}",
@@ -563,6 +570,8 @@ namespace Tgstation.Server.Tests.Live.Instance
Assert.AreEqual(DMApiConstants.MaximumTopicRequestLength, (uint)lastSize);
System.Console.WriteLine("TEST: Receiving Topic tests topics...");
// Receive
baseSize = 1;
nextPow = 0;
@@ -570,6 +579,7 @@ namespace Tgstation.Server.Tests.Live.Instance
while (!cancellationToken.IsCancellationRequested)
{
var currentSize = baseSize + (int)Math.Pow(2, nextPow);
System.Console.WriteLine($"Topic recieve limit test S:{currentSize}...");
var topicRequestResult = await TopicClientNoLogger.SendTopic(
IPAddress.Loopback,
$"tgs_integration_test_tactics4={TopicClient.SanitizeString(currentSize.ToString())}",