From 05aea3778573397c395e73dd12843b00aa0c323b Mon Sep 17 00:00:00 2001 From: June Rhodes Date: Wed, 25 Dec 2024 16:54:16 +1100 Subject: [PATCH] Use GC.KeepAlive to prevent the exited lambda from being GC'd (#113) --- UET/BuildTrimmedLocally.ps1 | 12 ------------ UET/Redpoint.Uba/DefaultUbaServer.cs | 17 ++++++++++------- .../DefaultReleaseUploader.cs | 2 +- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/UET/BuildTrimmedLocally.ps1 b/UET/BuildTrimmedLocally.ps1 index 689cb750..1b4281e8 100644 --- a/UET/BuildTrimmedLocally.ps1 +++ b/UET/BuildTrimmedLocally.ps1 @@ -3,18 +3,6 @@ $PackageVersion = "$($Timestamp.Year).$($Timestamp.DayOfYear + 1000).$(($Timesta Push-Location $PSScriptRoot\.. try { - dotnet msbuild -restore -p:RuntimeIdentifier=win-x86 -p:Configuration=Release -p:Platform=x86 -p:BaseUetVersionSuffix="-dev" -p:BaseUetVersion=$PackageVersion -p:PackageVersion=$PackageVersion UET/Redpoint.AutoDiscovery.Win32/Redpoint.AutoDiscovery.Win32.csproj - if ($LastExitCode -ne 0) { - exit $LastExitCode - } - dotnet msbuild -restore -p:RuntimeIdentifier=win-x64 -p:Configuration=Release -p:Platform=x64 -p:BaseUetVersionSuffix="-dev" -p:BaseUetVersion=$PackageVersion -p:PackageVersion=$PackageVersion UET/Redpoint.AutoDiscovery.Win64/Redpoint.AutoDiscovery.Win64.csproj - if ($LastExitCode -ne 0) { - exit $LastExitCode - } - dotnet msbuild -restore -t:Publish -p:Configuration=Release -p:Platform=AnyCPU -p:UsePrebuiltLibsForAutoDiscovery=true -p:BaseUetVersionSuffix="-dev" -p:BaseUetVersion=$PackageVersion -p:PackageVersion=$PackageVersion UET/Redpoint.AutoDiscovery/Redpoint.AutoDiscovery.csproj - if ($LastExitCode -ne 0) { - exit $LastExitCode - } dotnet msbuild -restore -t:Publish -p:RuntimeIdentifier=win-x64 -p:UsePrebuiltLibsForAutoDiscovery=true -p:Configuration=Release -p:BaseUetVersionSuffix="-dev" -p:BaseUetVersion=$PackageVersion -p:PackageVersion=$PackageVersion UET/uet/uet.csproj if ($LastExitCode -ne 0) { exit $LastExitCode diff --git a/UET/Redpoint.Uba/DefaultUbaServer.cs b/UET/Redpoint.Uba/DefaultUbaServer.cs index 81e1ef04..a022e8c0 100644 --- a/UET/Redpoint.Uba/DefaultUbaServer.cs +++ b/UET/Redpoint.Uba/DefaultUbaServer.cs @@ -257,16 +257,16 @@ private async Task RunProcessAsync( Func createProcessOnServer, bool isRemoteExecution) { + // Create the gate that we can wait on until the process exits. + var exitedGate = new Gate(); + ExitCallback exited = (nint userdata, nint handle) => + { + exitedGate.Open(); + }; + var isRequeued = false; try { - // Create the gate that we can wait on until the process exits. - var exitedGate = new Gate(); - ExitCallback exited = (nint userdata, nint handle) => - { - exitedGate.Open(); - }; - // Try to set the description. var description = "Unknown"; description = Path.GetFileName(descriptor.ProcessSpecification.Arguments.Last().LogicalValue); @@ -454,6 +454,9 @@ private async Task RunProcessAsync( { Interlocked.Decrement(ref _processesExecutingLocally); } + + // Prevent the exited callback from being garbage collected early in trimmed UET. + GC.KeepAlive(exited); } } diff --git a/UET/uet/Commands/Internal/CreateGitHubRelease/DefaultReleaseUploader.cs b/UET/uet/Commands/Internal/CreateGitHubRelease/DefaultReleaseUploader.cs index 80e300ef..68c76f6b 100644 --- a/UET/uet/Commands/Internal/CreateGitHubRelease/DefaultReleaseUploader.cs +++ b/UET/uet/Commands/Internal/CreateGitHubRelease/DefaultReleaseUploader.cs @@ -100,7 +100,7 @@ The other files in this release exist so they can be fetched on-demand by UET. # for Windows .\uet.exe upgrade - # for macOS + # for macOS or Linux chmod a+x ./uet ./uet upgrade ```