runtime: PowerShell crash on exit in Windows containers

Description

This is a really strange one. In the latest builds of 6.0 Preview 5, PowerShell 7 will crash on exit after it has run for a certain amount of time. I have attempted to configure the container to collect a crash dump but nothing gets output by WER. I think the underlying issue could be GC-related.

Repro steps

Dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:20H2

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ARG DOTNET_SDK_VERSION=6.0.100-preview.5.21275.4

RUN `
    # Retrieve .NET SDK
    Invoke-WebRequest -OutFile dotnet.zip https://dotnetcli.azureedge.net/dotnet/Sdk/$Env:DOTNET_SDK_VERSION/dotnet-sdk-$Env:DOTNET_SDK_VERSION-win-x64.zip; `
    mkdir 'C:\Program Files\dotnet'; `
    tar -C 'C:\Program Files\dotnet' -oxzf dotnet.zip; `
    Remove-Item -Force dotnet.zip;
RUN `
    # Install PowerShell global tool
    $powershell_version = '7.2.0-preview.5'; `
    Invoke-WebRequest -OutFile PowerShell.Windows.x64.$powershell_version.nupkg https://pwshtool.blob.core.windows.net/tool/$powershell_version/PowerShell.Windows.x64.$powershell_version.nupkg; `
    & 'C:\Program Files\dotnet\dotnet.exe' tool install --add-source . --tool-path 'C:\Program Files\powershell' --version $powershell_version PowerShell.Windows.x64; `
    & 'C:\Program Files\dotnet\dotnet.exe' nuget locals all --clear;

RUN setx /M PATH '%PATH%;C:\Program Files\powershell'
  1. Save the above contents to a file named Dockerfile in an empty folder and set that folder as current directory in command line.
  2. docker build -t test .
  3. docker run --rm test pwsh -Command "Start-Sleep -s 15"

Result:

Fatal error. Internal CLR error. (0x80131506)

If you set the sleep value in step 3 to 10 seconds instead of 15, there is no crash.

Configuration

Repro requires a Windows 10 machine (version 20H2+) with Docker installed and configured to target Windows containers.

Regression?

YES

~I’m still narrowing down which build this regressed in. But here’s what I know. It works in SDK build 6.0.100-preview.5.21262.1 and fails in build 6.0.100-preview.5.21275.4.~

This regression was introduced in build 6.0.100-preview.5.21264.5. The crash does not occur in the previous build, 6.0.100-preview.5.21264.4.

Other information

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

Ok great, it should be included in preview6!

I can confirm that cherry picking the above mentioned fix into the runtime state used by the repro and using rebuilt runtime fixed the problem.

Thank you @rjmholt.

Here is a stack trace at the crash, it occurs because the MethodTable is NULL.

0:000> k
 # Child-SP          RetAddr           Call Site
00 000000c3`64b7eb28 00007ff9`c47ec642 coreclr!MethodTable::GetModule [D:\workspace\_work\1\s\src\coreclr\vm\methodtable.cpp @ 372] 
01 (Inline Function) --------`-------- coreclr!MethodDesc::GetModule_NoLogging+0x2e [D:\workspace\_work\1\s\src\coreclr\vm\method.cpp @ 1521] 
02 000000c3`64b7eb30 00007ff9`c4838233 coreclr!ZapSig::EncodeMethod+0x52 [D:\workspace\_work\1\s\src\coreclr\vm\zapsig.cpp @ 1253] 
03 000000c3`64b7ebb0 00007ff9`c4838864 coreclr!MulticoreJitRecorder::WriteOutput+0x13b [D:\workspace\_work\1\s\src\coreclr\vm\multicorejit.cpp @ 409] 
04 000000c3`64b7ed60 00007ff9`c4837f63 coreclr!MulticoreJitRecorder::WriteOutput+0xa8 [D:\workspace\_work\1\s\src\coreclr\vm\multicorejit.cpp @ 155] 
05 000000c3`64b7edc0 00007ff9`c4788511 coreclr!MulticoreJitRecorder::StopProfile+0x37 [D:\workspace\_work\1\s\src\coreclr\vm\multicorejit.cpp @ 925] 
06 000000c3`64b7edf0 00007ff9`c46deec9 coreclr!MulticoreJitManager::StopProfile+0xa9559 [D:\workspace\_work\1\s\src\coreclr\vm\multicorejit.cpp @ 1292] 
07 000000c3`64b7ee90 00007ff9`c46de3cd coreclr!MulticoreJitManager::StopProfileAll+0x3d [D:\workspace\_work\1\s\src\coreclr\vm\multicorejit.cpp @ 1485] 
08 000000c3`64b7eee0 00007ff9`c46de000 coreclr!EEShutDown+0x35 [D:\workspace\_work\1\s\src\coreclr\vm\ceemain.cpp @ 1715] 
09 000000c3`64b7ef20 00007ff9`c46eea79 coreclr!CorHost2::UnloadAppDomain2+0x40 [D:\workspace\_work\1\s\src\coreclr\vm\corhost.cpp @ 922] 
0a 000000c3`64b7ef50 00007ff9`f89e9527 coreclr!coreclr_shutdown_2+0x59 [D:\workspace\_work\1\s\src\coreclr\dlls\mscoree\unixinterface.cpp @ 357] 
0b (Inline Function) --------`-------- hostpolicy!coreclr_t::shutdown+0x45 [D:\workspace\_work\1\s\src\native\corehost\hostpolicy\coreclr.cpp @ 132] 
0c 000000c3`64b7efa0 00007ff9`f89e97dc hostpolicy!run_app_for_context+0x5c7 [D:\workspace\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 264] 
0d 000000c3`64b7f140 00007ff9`f89ea178 hostpolicy!run_app+0x3c [D:\workspace\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 284] 
0e 000000c3`64b7f180 00007ffa`0560bf58 hostpolicy!corehost_main+0x108 [D:\workspace\_work\1\s\src\native\corehost\hostpolicy\hostpolicy.cpp @ 430] 
0f 000000c3`64b7f330 00007ffa`0560ec97 hostfxr!execute_app+0x2e8 [D:\workspace\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 146] 
10 000000c3`64b7f430 00007ffa`05610fc2 hostfxr!`anonymous namespace'::read_config_and_execute+0x97 [D:\workspace\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 520] 
11 000000c3`64b7f530 00007ffa`0560f2ed hostfxr!fx_muxer_t::handle_exec_host_command+0x152 [D:\workspace\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 1001] 
12 000000c3`64b7f5d0 00007ffa`05608ceb hostfxr!fx_muxer_t::execute+0x47d [D:\workspace\_work\1\s\src\native\corehost\fxr\fx_muxer.cpp @ 566] 
13 000000c3`64b7f710 00007ff6`9c1117cc hostfxr!hostfxr_main_startupinfo+0xab [D:\workspace\_work\1\s\src\native\corehost\fxr\hostfxr.cpp @ 61] 
14 000000c3`64b7f810 00007ff6`9c111b3b apphost!exe_start+0x8bc [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp @ 236] 
15 000000c3`64b7f9e0 00007ff6`9c112fe8 apphost!wmain+0xab [D:\workspace\_work\1\s\src\native\corehost\corehost.cpp @ 305] 
16 (Inline Function) --------`-------- apphost!invoke_main+0x22 [D:\agent\_work\10\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 90] 
17 000000c3`64b7fa10 00007ffa`33e37034 apphost!__scrt_common_main_seh+0x10c [D:\agent\_work\10\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
18 000000c3`64b7fa50 00007ffa`35e02651 KERNEL32!BaseThreadInitThunk+0x14 [clientcore\base\win32\client\thread.c @ 64] 
19 000000c3`64b7fa80 00000000`00000000 ntdll!RtlUserThreadStart+0x21 [minkernel\ntdll\rtlstrt.c @ 1153] 

@mangod9 you should be able to find a pwsh build to repro with here. AFAIK, the repro is essentially to run pwsh for a while and then exit it with exit