Skip to content
Snippets Groups Projects
Commit 6ea4380d authored by Jan Tattermusch's avatar Jan Tattermusch Committed by GitHub
Browse files

Merge pull request #8047 from jtattermusch/coreclr_unloading

Add shutdown hook for CoreCLR
parents e57904bf 93f62aff
No related branches found
No related tags found
No related merge requests found
...@@ -351,11 +351,11 @@ namespace Grpc.Core ...@@ -351,11 +351,11 @@ namespace Grpc.Core
{ {
if (!hooksRegistered) if (!hooksRegistered)
{ {
// TODO(jtattermusch): register shutdownhooks for CoreCLR as well #if NETSTANDARD1_5
#if !NETSTANDARD1_5 System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += (assemblyLoadContext) => { HandleShutdown(); };
#else
AppDomain.CurrentDomain.ProcessExit += ShutdownHookHandler; AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => { HandleShutdown(); };
AppDomain.CurrentDomain.DomainUnload += ShutdownHookHandler; AppDomain.CurrentDomain.DomainUnload += (sender, eventArgs) => { HandleShutdown(); };
#endif #endif
} }
hooksRegistered = true; hooksRegistered = true;
...@@ -363,9 +363,9 @@ namespace Grpc.Core ...@@ -363,9 +363,9 @@ namespace Grpc.Core
} }
/// <summary> /// <summary>
/// Handler for AppDomain.DomainUnload and AppDomain.ProcessExit hooks. /// Handler for AppDomain.DomainUnload, AppDomain.ProcessExit and AssemblyLoadContext.Unloading hooks.
/// </summary> /// </summary>
private static void ShutdownHookHandler(object sender, EventArgs e) private static void HandleShutdown()
{ {
Task.WaitAll(GrpcEnvironment.ShutdownChannelsAsync(), GrpcEnvironment.KillServersAsync()); Task.WaitAll(GrpcEnvironment.ShutdownChannelsAsync(), GrpcEnvironment.KillServersAsync());
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
"netstandard1.5": { "netstandard1.5": {
"dependencies": { "dependencies": {
"NETStandard.Library": "1.6.0", "NETStandard.Library": "1.6.0",
"System.Runtime.Loader": "4.0.0",
"System.Threading.Thread": "4.0.0" "System.Threading.Thread": "4.0.0"
} }
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
"netstandard1.5": { "netstandard1.5": {
"dependencies": { "dependencies": {
"NETStandard.Library": "1.6.0", "NETStandard.Library": "1.6.0",
"System.Runtime.Loader": "4.0.0",
"System.Threading.Thread": "4.0.0" "System.Threading.Thread": "4.0.0"
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment