Fix .NET 10 CLR shutdown hook breaking change#7964
Conversation
Aaronontheweb
left a comment
There was a problem hiding this comment.
Had a conceptual question about Windows support but otherwise this looks good
| /// Handles SIGTERM and SIGHUP signals, plus ProcessExit as fallback. | ||
| /// This is required for .NET 10 compatibility where ProcessExit no longer fires on SIGTERM. | ||
| /// </summary> | ||
| internal sealed class PosixTerminationSignalHandler : ITerminationSignalHandler |
There was a problem hiding this comment.
Dumb question on my part so I feel like I must be missing it - what do we do for Windows?
| <PackageReference Include="Xunit.SkippableFact" Version="1.4.13" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Exclude System.Linq.Async for .NET 10+ as it conflicts with built-in BCL methods --> |
| { | ||
| _callback = onTerminationSignal; | ||
|
|
||
| // Register POSIX signals (works on Unix/macOS/Windows in .NET 6+) |
There was a problem hiding this comment.
Ah ok, so even though this is named "PosixSignalRegistration" it actually works on Windows too?
There was a problem hiding this comment.
Yes from my research, I might actually be wrong. It does appear that way from my probings. Would be nice to hear from other people about this.
There was a problem hiding this comment.
the tests pass on Windows so I think it should be fine.
There was a problem hiding this comment.
It isn't supported in IOS and not all signals are translated between windows and linux.
* Fix .NET 10 CLR shutdown hook breaking change * fix global.json * Fix warning as errors * Install .NET SDK 8.0 * Add very targetted .NET 10 CI/CD run * Fix CI/CD script * Code fix * Revert .NET 10 CI/CD integration (will be moved to a new PR) * whitespace cleanup --------- Co-authored-by: Aaron Stannard <aaron@petabridge.com>
* Fix .NET 10 CLR shutdown hook breaking change * fix global.json * Fix warning as errors * Install .NET SDK 8.0 * Add very targetted .NET 10 CI/CD run * Fix CI/CD script * Code fix * Revert .NET 10 CI/CD integration (will be moved to a new PR) * whitespace cleanup --------- Co-authored-by: Aaron Stannard <aaron@petabridge.com>
Fixes #7963
Fix CoordinatedShutdown CLR Termination Hook for .NET 10 Compatibility
Summary
This PR addresses a breaking change in .NET 10 where
AppDomain.ProcessExitis no longer raised when termination signals (SIGTERM, SIGHUP) are received. This would have causedCoordinatedShutdownto fail silently in containerized environments (Kubernetes, Docker) when running on .NET 10+.Breaking Change Reference
Changes
New Termination Signal Handler Abstraction
Introduced
ITerminationSignalHandlerinterface with two implementations:PosixTerminationSignalHandler(.NET 6+): UsesPosixSignalRegistrationto handle SIGTERM/SIGHUP signals directly, withProcessExitas fallbackLegacyTerminationSignalHandler(netstandard2.0): UsesProcessExitonly (maintains backward compatibility)Key features:
context.Cancel = trueto allow graceful shutdown time before OS terminatesInterlocked.CompareExchangeto ensure callback only executes onceFiles Modified/Created
src/core/Akka/Actor/TerminationSignalHandler.cssrc/core/Akka/Actor/CoordinatedShutdown.csInitClrHookto use abstractionsrc/core/Akka.Tests/Actor/TerminationSignalHandlerSpec.cssrc/core/Akka.Tests/Akka.Tests.csprojAdditional .NET 10 Test Fixes
System.Linq.Async conflict: Excluded transitive
System.Linq.Asyncpackage for .NET 10+ to resolve ambiguous method calls with BCL's built-inSystem.Linq.AsyncEnumerableConfigurationSpec exclusion: Added
CORECLRdefine for .NET 10 to properly exclude App.config-based tests (which only work on .NET Framework)Test Coverage
New tests verify:
run-by-clr-shutdown-hookis enabled/disabledClrExitReasonis set correctly during CLR shutdownBackward Compatibility
LegacyTerminationSignalHandlerPosixTerminationSignalHandlerPosixTerminationSignalHandler