Fix .NET 10 CLR shutdown hook breaking change #7964
+471
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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