From bf313e9e285e1c5e267f324dd8f3e10a00c91833 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 17 Aug 2020 21:42:09 -0400 Subject: [PATCH] Stop using TaskCreationOptions.LongRunning --- .../Components/Chat/Providers/IrcProvider.cs | 11 ++++--- .../Repository/LibGit2RepositoryFactory.cs | 5 +-- .../Components/Repository/Repository.cs | 26 ++++++++-------- .../Components/StaticFiles/Configuration.cs | 6 ++-- src/Tgstation.Server.Host/IO/Console.cs | 8 ++--- .../IO/DefaultIOManager.cs | 31 +++++++++++-------- .../IO/PosixSymlinkFactory.cs | 4 +-- .../IO/WindowsSymlinkFactory.cs | 4 +-- .../Security/WindowsSystemIdentity.cs | 7 +++-- .../Security/WindowsSystemIdentityFactory.cs | 5 +-- src/Tgstation.Server.Host/System/Process.cs | 3 +- .../System/WindowsProcessFeatures.cs | 3 +- 12 files changed, 62 insertions(+), 51 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs index aa63d7b6fa..02e413701a 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Providers/IrcProvider.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Extensions; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; using Tgstation.Server.Host.System; @@ -302,7 +303,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers Logger.LogTrace("Exiting listening task..."); }, cancellationToken, - TaskCreationOptions.LongRunning, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); await nickCheckCompleteTcs.Task.ConfigureAwait(false); @@ -430,7 +431,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers } }, cancellationToken, - TaskCreationOptions.LongRunning, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current) .ConfigureAwait(false); await HardDisconnect(cancellationToken).ConfigureAwait(false); @@ -472,7 +473,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers } }, cancellationToken, - TaskCreationOptions.None, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); await Task.WhenAny( @@ -545,7 +546,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers }) .ToList(); } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public override Task SendMessage(ulong channelId, string message, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -573,7 +574,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers { Logger.LogWarning(e, "Unable to send to channel {0}!", channelName); } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public override async Task> SendUpdateMessage( diff --git a/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs b/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs index 4e24002bb7..b09fbc9c45 100644 --- a/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs +++ b/src/Tgstation.Server.Host/Components/Repository/LibGit2RepositoryFactory.cs @@ -5,6 +5,7 @@ using System; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; namespace Tgstation.Server.Host.Components.Repository @@ -46,7 +47,7 @@ namespace Tgstation.Server.Host.Components.Repository return new LibGit2Sharp.Repository(path); }, cancellationToken, - TaskCreationOptions.LongRunning, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } @@ -63,7 +64,7 @@ namespace Tgstation.Server.Host.Components.Repository logger.LogTrace(ex, "Suppressing clone cancellation exception"); cancellationToken.ThrowIfCancellationRequested(); } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public CredentialsHandler GenerateCredentialsHandler(string username, string password) => (a, b, supportedCredentialTypes) => diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index 7eb127fe83..53e7d5b50b 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -375,7 +375,7 @@ namespace Tgstation.Server.Host.Components.Repository } libGitRepo.RemoveUntrackedFiles(); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); if (result.Status == MergeStatus.Conflicts) { @@ -389,7 +389,7 @@ namespace Tgstation.Server.Host.Components.Repository await Task.Factory.StartNew(() => libGitRepo.Commit(commitMessage, sig, sig, new CommitOptions { PrettifyMessage = true - }), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }), cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } await eventConsumer.HandleEvent( @@ -420,7 +420,7 @@ namespace Tgstation.Server.Host.Components.Repository { libGitRepo.RemoveUntrackedFiles(); RawCheckout(committish, progressReporter, cancellationToken); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } /// @@ -453,7 +453,7 @@ namespace Tgstation.Server.Host.Components.Repository { cancellationToken.ThrowIfCancellationRequested(); } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } /// @@ -492,7 +492,7 @@ namespace Tgstation.Server.Host.Components.Repository { libGitRepo.Branches.Remove(branch); } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public async Task ResetToOrigin(Action progressReporter, CancellationToken cancellationToken) @@ -530,7 +530,7 @@ namespace Tgstation.Server.Host.Components.Repository { OnCheckoutProgress = CheckoutProgressHandler(progressReporter) }); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public async Task CopyTo(string path, CancellationToken cancellationToken) @@ -550,7 +550,7 @@ namespace Tgstation.Server.Host.Components.Repository cancellationToken.ThrowIfCancellationRequested(); return libGitRepo.Head.TrackedBranch.Tip.Sha; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public async Task MergeOrigin(string committerName, string committerEmail, Action progressReporter, CancellationToken cancellationToken) @@ -601,7 +601,7 @@ namespace Tgstation.Server.Host.Components.Repository } libGitRepo.RemoveUntrackedFiles(); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); if (result.Status == MergeStatus.Conflicts) { @@ -643,7 +643,7 @@ namespace Tgstation.Server.Host.Components.Repository libGitRepo.Config.Set("user.name", committerName); cancellationToken.ThrowIfCancellationRequested(); libGitRepo.Config.Set("user.email", committerEmail); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); try @@ -668,7 +668,7 @@ namespace Tgstation.Server.Host.Components.Repository { OnCheckoutProgress = CheckoutProgressHandler(progress => progressReporter(progress / 10)) }); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } void FinalReporter(int progress) => progressReporter((int)(((float)progress) / 100 * 90)); @@ -711,7 +711,7 @@ namespace Tgstation.Server.Host.Components.Repository logger.LogWarning(e, "Unable to make synchronization push!"); return false; } - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); } /// @@ -732,7 +732,7 @@ namespace Tgstation.Server.Host.Components.Repository if (libGitRepo.Lookup(committish) != null) return true; return false; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task ShaIsParent(string sha, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -770,6 +770,6 @@ namespace Tgstation.Server.Host.Components.Repository startSha); return false; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index c18aee9d6a..de5bfb0174 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -287,7 +287,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false)) if (systemIdentity == null) - await Task.Factory.StartNew(ReadImpl, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + await Task.Factory.StartNew(ReadImpl, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); else await systemIdentity.RunImpersonated(ReadImpl, cancellationToken).ConfigureAwait(false); @@ -418,7 +418,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false)) if (systemIdentity == null) - await Task.Factory.StartNew(WriteImpl, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + await Task.Factory.StartNew(WriteImpl, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); else await systemIdentity.RunImpersonated(WriteImpl, cancellationToken).ConfigureAwait(false); @@ -436,7 +436,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken).ConfigureAwait(false)) if (systemIdentity == null) - await Task.Factory.StartNew(DoCreate, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current).ConfigureAwait(false); + await Task.Factory.StartNew(DoCreate, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current).ConfigureAwait(false); else await systemIdentity.RunImpersonated(DoCreate, cancellationToken).ConfigureAwait(false); diff --git a/src/Tgstation.Server.Host/IO/Console.cs b/src/Tgstation.Server.Host/IO/Console.cs index f8c8162d29..66f1908e37 100644 --- a/src/Tgstation.Server.Host/IO/Console.cs +++ b/src/Tgstation.Server.Host/IO/Console.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -61,7 +61,7 @@ namespace Tgstation.Server.Host.IO { CheckAvailable(); global::System.Console.Read(); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task ReadLineAsync(bool usePasswordChar, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -97,7 +97,7 @@ namespace Tgstation.Server.Host.IO cancellationToken.ThrowIfCancellationRequested(); global::System.Console.WriteLine(); return passwordBuilder.ToString(); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task WriteAsync(string text, bool newLine, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -113,6 +113,6 @@ namespace Tgstation.Server.Host.IO global::System.Console.WriteLine(text); else global::System.Console.Write(text); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs index 92421074ba..d63c32753c 100644 --- a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -24,6 +24,11 @@ namespace Tgstation.Server.Host.IO /// public const int DefaultBufferSize = 4096; + /// + /// The used to spawn s for potentially long running, blocking operations. + /// + public const TaskCreationOptions BlockingTaskCreationOptions = TaskCreationOptions.None; + /// /// Recursively empty a directory /// @@ -149,7 +154,7 @@ namespace Tgstation.Server.Host.IO } /// - public Task CreateDirectory(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => Directory.CreateDirectory(ResolvePath(path)), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + public Task CreateDirectory(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => Directory.CreateDirectory(ResolvePath(path)), cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task DeleteDirectory(string path, CancellationToken cancellationToken) @@ -162,18 +167,18 @@ namespace Tgstation.Server.Host.IO return Task.Factory.StartNew( () => NormalizeAndDelete(di, cancellationToken), cancellationToken, - TaskCreationOptions.LongRunning, + BlockingTaskCreationOptions, TaskScheduler.Current); } /// - public Task DeleteFile(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => File.Delete(ResolvePath(path)), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + public Task DeleteFile(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => File.Delete(ResolvePath(path)), cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// - public Task FileExists(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => File.Exists(ResolvePath(path)), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + public Task FileExists(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => File.Exists(ResolvePath(path)), cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// - public Task DirectoryExists(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => Directory.Exists(ResolvePath(path)), cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + public Task DirectoryExists(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => Directory.Exists(ResolvePath(path)), cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public string GetDirectoryName(string path) => Path.GetDirectoryName(path ?? throw new ArgumentNullException(nameof(path))); @@ -201,7 +206,7 @@ namespace Tgstation.Server.Host.IO } return results; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task MoveFile(string source, string destination, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -211,7 +216,7 @@ namespace Tgstation.Server.Host.IO source = ResolvePath(source ?? throw new ArgumentNullException(nameof(source))); destination = ResolvePath(destination); File.Move(source, destination); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task MoveDirectory(string source, string destination, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -221,7 +226,7 @@ namespace Tgstation.Server.Host.IO source = ResolvePath(source ?? throw new ArgumentNullException(nameof(source))); destination = ResolvePath(destination); Directory.Move(source, destination); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public async Task ReadAllBytes(string path, CancellationToken cancellationToken) @@ -261,7 +266,7 @@ namespace Tgstation.Server.Host.IO } return (IReadOnlyList)results; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task> GetFiles(string path, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -276,7 +281,7 @@ namespace Tgstation.Server.Host.IO } return (IReadOnlyList)results; - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public async Task DownloadFile(Uri url, CancellationToken cancellationToken) @@ -312,7 +317,7 @@ namespace Tgstation.Server.Host.IO using var ms = new MemoryStream(zipFileBytes); using var archive = new ZipArchive(ms, ZipArchiveMode.Read); archive.ExtractToDirectory(path); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); /// public bool PathContainsParentAccess(string path) => path?.Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }).Any(x => x == "..") ?? throw new ArgumentNullException(nameof(path)); @@ -323,6 +328,6 @@ namespace Tgstation.Server.Host.IO path = ResolvePath(path ?? throw new ArgumentNullException(nameof(path))); var fileInfo = new FileInfo(path); return new DateTimeOffset(fileInfo.LastWriteTimeUtc); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs b/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs index 4499d5ac13..997fa3d005 100644 --- a/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs +++ b/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs @@ -1,4 +1,4 @@ -using Mono.Unix; +using Mono.Unix; using System; using System.IO; using System.Threading; @@ -28,6 +28,6 @@ namespace Tgstation.Server.Host.IO fsInfo = new UnixDirectoryInfo(targetPath); cancellationToken.ThrowIfCancellationRequested(); fsInfo.CreateSymbolicLink(linkPath); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs index a1426d7663..99f4221b6f 100644 --- a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs +++ b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs @@ -1,4 +1,4 @@ -using BetterWin32Errors; +using BetterWin32Errors; using System; using System.IO; using System.Threading; @@ -37,6 +37,6 @@ namespace Tgstation.Server.Host.IO cancellationToken.ThrowIfCancellationRequested(); if (!NativeMethods.CreateSymbolicLink(linkPath, targetPath, flags)) throw new Win32Exception(); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs index aad76f2360..a833dc4d14 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs @@ -1,8 +1,9 @@ -using System; +using System; using System.DirectoryServices.AccountManagement; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Security { @@ -90,6 +91,6 @@ namespace Tgstation.Server.Host.Security if (identity == null) throw new InvalidOperationException("Impersonate using a UserPrincipal based WindowsSystemIdentity!"); WindowsIdentity.RunImpersonated(identity.AccessToken, action); - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } -} \ No newline at end of file +} diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs index 1b9e64e4e6..fa5eb5924b 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentityFactory.cs @@ -5,6 +5,7 @@ using System.DirectoryServices.AccountManagement; using System.Security.Principal; using System.Threading; using System.Threading.Tasks; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Security @@ -88,7 +89,7 @@ namespace Tgstation.Server.Host.Security return null; return (ISystemIdentity)new WindowsSystemIdentity(principal); }, - cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); /// public Task CreateSystemIdentity(string username, string password, CancellationToken cancellationToken) => Task.Factory.StartNew(() => @@ -114,6 +115,6 @@ namespace Tgstation.Server.Host.Security using var handle = new SafeAccessTokenHandle(token); return (ISystemIdentity)new WindowsSystemIdentity( new WindowsIdentity(handle.DangerousGetHandle())); // https://github.com/dotnet/corefx/blob/6ed61acebe3214fcf79b4274f2bb9b55c0604a4d/src/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs#L271 - }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + }, cancellationToken, DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/System/Process.cs b/src/Tgstation.Server.Host/System/Process.cs index 60734cf725..e034e1aedc 100644 --- a/src/Tgstation.Server.Host/System/Process.cs +++ b/src/Tgstation.Server.Host/System/Process.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Extensions; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.System { @@ -97,7 +98,7 @@ namespace Tgstation.Server.Host.System } }, default, // DCT: None available - TaskCreationOptions.LongRunning, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); logger.LogTrace("Created process ID: {0}", Id); diff --git a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs index a01d5e850f..f200be8192 100644 --- a/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs +++ b/src/Tgstation.Server.Host/System/WindowsProcessFeatures.cs @@ -7,6 +7,7 @@ using System.Management; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Jobs; namespace Tgstation.Server.Host.System @@ -119,7 +120,7 @@ namespace Tgstation.Server.Host.System throw new Win32Exception(); }, cancellationToken, - TaskCreationOptions.LongRunning, + DefaultIOManager.BlockingTaskCreationOptions, TaskScheduler.Current); } }