Skip to content

Commit

Permalink
Use GC.KeepAlive to prevent the exited lambda from being GC'd (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
hach-que authored Dec 25, 2024
1 parent 0f4d261 commit 05aea37
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
12 changes: 0 additions & 12 deletions UET/BuildTrimmedLocally.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions UET/Redpoint.Uba/DefaultUbaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ private async Task RunProcessAsync(
Func<nint, nint> 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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit 05aea37

Please sign in to comment.