Skip to content

Commit 982dc8a

Browse files
Copilotdanmoseley
andauthored
Disable EnsureEnvironmentExitDoesntHang on .NET Framework (dotnet#125912)
`ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang` fails on .NET Framework because `System.Console.ControlCHooker.Unhook()` throws `IOException: The parameter is incorrect` during process finalization, causing an unhandled exception (exit code -532462766 / EXCEPTION_COMPLUS). This is a known .NET Framework shutdown limitation. ## Changes - Added `[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NET Framework shutdown issue")]` to `EnsureEnvironmentExitDoesntHang` — consistent with the existing skip on the related `EnsureEnvironmentExitCode` test - Simplified the test body: removed the now-dead `expectedExitCode = PlatformDetection.IsNetFramework ? 0 : 125` conditional, inlining `125` directly > [!NOTE] > This PR description was generated with AI assistance (GitHub Copilot). <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> ---- *This section details on the original issue you should resolve* <issue_title>Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang fails on .NET Framework</issue_title> <issue_description>## Build Information Build: https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1143743 Build error leg or test failing: Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang Pull request: dotnet#119515 Console excerpt: ``` Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL] Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code was -532462766 but it should have been 0 Stack Trace: /_/src/arcade/src/Microsoft.DotNet.RemoteExecutor/src/RemoteInvokeHandle.cs(242,0): at Microsoft.DotNet.RemoteExecutor.RemoteInvokeHandle.Dispose(Boolean disposing) /_/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeExitTests.cs(223,0): at Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang() ``` -532462766 corresponds with EXCEPTION_COMPLUS. ```json { "ErrorMessage": "ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang [FAIL]", "ErrorPattern": "", "BuildRetry": false, "ExcludeConsoleLog": false } ``` <!-- Known issue validation start --> ### Known issue validation **Build: 🔎** https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743 **Error message validated:** `[Microsoft\.DotNet\.RemoteExecutor\.RemoteExecutionException : Exit code was -532462766 but it should have been 0.*EnsureEnvironmentExitDoesntHang()`] **Result validation:** ❌ Known issue did not match with the provided build. **Validation performed at:** 9/10/2025 6:12:29 PM UTC <!-- Known issue validation end --> <!-- Known issue validation start --> ### Known issue validation **Build: 🔎** https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743 **Error message validated:** `[Microsoft.DotNet.RemoteExecutor.RemoteExecutionException : Exit code was -532462766 but it should have been 0`] **Result validation:** ✅ Known issue matched with the provided build. **Validation performed at:** 9/10/2025 7:05:39 PM UTC <!-- Known issue validation end --> <!--Known issue error report start --> ### Report |Build|Definition|Test|Pull Request| |---|---|---|---| |[1143743](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743&view=ms.vss-test-web.build-test-results-tab&runId=31540798&resultId=103521)|dotnet/runtime#119515| #### Summary |24-Hour Hit Count|7-Day Hit Count|1-Month Count| |---|---|---| |1|1|1| <!--Known issue error report end --> <!-- Known issue validation start --> ### Known issue validation **Build: 🔎** https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743 **Error message validated:** `[at System.Console.ControlCHooker.Unhook`] **Result validation:** ✅ Known issue matched with the provided build. **Validation performed at:** 9/10/2025 7:07:38 PM UTC <!-- Known issue validation end --> <!--Known issue error report start --> ### Report |Build|Definition|Test|Pull Request| |---|---|---|---| |[1143743](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1143743&view=ms.vss-test-web.build-test-results-tab&runId=31540798&resultId=103521)|dotnet/runtime#119515| #### Summary |24-Hour Hit Count|7-Day Hit Count|1-Month Count| |---|---|---| |1|1|1| <!--Known issue error report end --> <!--Known issue error report start --> ### Report |Build|Definition|Test|Pull Request| |---|---|---|---| |[1174378](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1174378)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1174378&view=ms.vss-test-web.build-test-results-tab&runId=32501172&resultId=104197)|| |[1170349](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1170349)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitTests.EnsureEnvironmentExitDoesntHang](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1170349&view=ms.vss-test-web.build-test-results-tab&runId=32385630&resultId=103595)|dotnet/runtime#120603| |[1169444](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1169444)|dotnet/runtime|[Microsoft.Extensions.Hosting.Tests.ConsoleLifetimeExitT... </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes dotnet#119545 <!-- START COPILOT CODING AGENT TIPS --> --- ⌨️ Start Copilot coding agent tasks without leaving your editor — available in [VS Code](https://gh.io/cca-vs-code-docs), [Visual Studio](https://gh.io/cca-visual-studio-docs), [JetBrains IDEs](https://gh.io/cca-jetbrains-docs) and [Eclipse](https://gh.io/cca-eclipse-docs). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danmoseley <6385855+danmoseley@users.noreply.github.com>
1 parent 162722d commit 982dc8a

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/ConsoleLifetimeExitTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,9 @@ await Task.Run(() =>
205205
/// Tests that calling Environment.Exit from the "main" thread doesn't hang the process forever.
206206
/// </summary>
207207
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
208+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NET Framework shutdown issue")]
208209
public void EnsureEnvironmentExitDoesntHang()
209210
{
210-
// SIGTERM is only handled on net6.0+, so the workaround to "clobber" the exit code is still in place on .NET Framework
211-
int expectedExitCode = PlatformDetection.IsNetFramework ? 0 : 125;
212-
213211
using var remoteHandle = RemoteExecutor.Invoke(async () =>
214212
{
215213
await Host.CreateDefaultBuilder()
@@ -219,7 +217,7 @@ await Host.CreateDefaultBuilder()
219217
services.AddHostedService<EnsureEnvironmentExitDoesntHangWorker>();
220218
})
221219
.RunConsoleAsync();
222-
}, new RemoteInvokeOptions() { TimeOut = 30_000, ExpectedExitCode = expectedExitCode }); // give a 30 second time out, so if this does hang, it doesn't hang for the full timeout
220+
}, new RemoteInvokeOptions() { TimeOut = 30_000, ExpectedExitCode = 125 }); // give a 30 second time out, so if this does hang, it doesn't hang for the full timeout
223221
}
224222

225223
private class EnsureEnvironmentExitDoesntHangWorker : BackgroundService

0 commit comments

Comments
 (0)