Fix AssemblyLoadContext.Unloading and ProcessExit for Windows Docker containers ...
authorDaniel Harvey <dharvey@microsoft.com>
Thu, 29 Mar 2018 18:59:19 +0000 (11:59 -0700)
committerGitHub <noreply@github.com>
Thu, 29 Mar 2018 18:59:19 +0000 (11:59 -0700)
On Windows, we need to shutdown the EE when receiving a CTRL_CLOSE_EVENT to we run ProcessExit handlers and other code that relies on ProcessExit working (like AssemblyLoadContext.Unloading). One way we receive this event is when there's a running process in a docker container that has the stop command run against it.

src/vm/ceemain.cpp
src/vm/eeconfig.cpp

index b09d970..20b579a 100644 (file)
@@ -446,7 +446,13 @@ static BOOL WINAPI DbgCtrlCHandler(DWORD dwCtrlType)
     }
     else
 #endif // DEBUGGING_SUPPORTED
-    {         
+    {
+        if (dwCtrlType == CTRL_CLOSE_EVENT)
+        {
+            // Initiate shutdown so the ProcessExit handlers run
+            ForceEEShutdown(SCA_ReturnWhenShutdownComplete);
+        }
+
         g_fInControlC = true;     // only for weakening assertions in checked build.
         return FALSE;             // keep looking for a real handler.
     }
index a227437..1b44367 100644 (file)
@@ -166,7 +166,6 @@ void *EEConfig::operator new(size_t size)
     RETURN g_EEConfigMemory;
 }
 
-
 /**************************************************************/
 HRESULT EEConfig::Init()
 {
@@ -393,7 +392,6 @@ HRESULT EEConfig::Init()
     // statically link to EEConfig.
     CLRConfig::RegisterGetConfigValueCallback(&GetConfigValueCallback);
 
-
     return S_OK;
 }