From 19222c9d65e8eba3b81df1beb767f08fefe2f06d Mon Sep 17 00:00:00 2001 From: Dominion Date: Sat, 15 Apr 2023 15:12:06 -0400 Subject: [PATCH] Revert "Remove SafeHandle as referencing it does nothing" This reverts commit cafc29b51333b301789b2e8e7bb2e2442669f7a2. --- src/Tgstation.Server.Host/System/Process.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Tgstation.Server.Host/System/Process.cs b/src/Tgstation.Server.Host/System/Process.cs index 404d96fb36..192729e89a 100644 --- a/src/Tgstation.Server.Host/System/Process.cs +++ b/src/Tgstation.Server.Host/System/Process.cs @@ -42,6 +42,12 @@ namespace Tgstation.Server.Host.System /// readonly CancellationTokenSource readerCts; + /// + /// The . + /// + /// We keep this to prevent .NET from closing the real handle too soon. See https://stackoverflow.com/a/47656845 + readonly SafeProcessHandle safeHandle; + /// /// The resulting in the process' standard output/error text. /// @@ -69,6 +75,7 @@ namespace Tgstation.Server.Host.System this.handle = handle ?? throw new ArgumentNullException(nameof(handle)); // Do this fast because the runtime will bitch if we try to access it after it ends + safeHandle = handle.SafeHandle; Id = handle.Id; this.readerCts = readerCts; @@ -115,6 +122,7 @@ namespace Tgstation.Server.Host.System if (readTask != null) await readTask; + safeHandle.Dispose(); handle.Dispose(); }