Fatal error. Internal CLR error. (0x80131506) on Entity Framework running inside docker container on arm32

166 Views Asked by At

I'm trying to containerize an existing application I wrote that I've been running on my Raspberry Pi 4.

The app is running .NET 8 using Entity Framework postgres (all packages are updated to their latest release versions).

The postgres database server is external to the Raspberry Pi on the cloud.

I'm running into the error:

Unhandled exception. System.Runtime.InteropServices.COMException (0x8007054F): An internal error occurred.
 (0x8007054F)
   at System.Threading.WaitHandle.WaitOneCore(IntPtr waitHandle, Int32 millisecondsTimeout)
   at System.Threading.WaitHandle.WaitOneNoCheck(Int32 millisecondsTimeout)
   at System.Threading.PortableThreadPool.GateThread.GateThreadStart()
   at System.Threading.Thread.StartCallback()
Fatal error. Internal CLR error. (0x80131506)
   at System.Threading.WaitHandle.WaitOneCore(IntPtr, Int32)
   at System.Threading.WaitHandle.WaitOneNoCheck(Int32)
   at System.Threading.PortableThreadPool+GateThread.GateThreadStart()
   at System.Threading.Thread.StartCallback()

I've been trying to figure this out for 2 days now so I'll just dump all the info I have here and hopefully someone else has run into something similar before because I'm completely stuck.

DOCKERFILE:

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Debug
WORKDIR /src
COPY ["VeriBot/VeriBot.csproj", "VeriBot/"]
RUN dotnet restore "VeriBot/VeriBot.csproj"
COPY . .
WORKDIR "/src/VeriBot"
RUN dotnet build "VeriBot.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Debug
RUN dotnet publish "VeriBot.csproj" --self-contained true -c $BUILD_CONFIGURATION -o /app/publish -r linux-arm /p:PublishSingleFile=true /p:DebugType=None /p:DebugSymbols=false 

FROM --platform=linux/arm/v7 mcr.microsoft.com/dotnet/runtime:8.0-bookworm-slim-arm32v7 AS final
ENV DOTNET_RUNNING_IN_CONTAINER=true \
        COMPlus_EnableDiagnostics=0
USER $APP_UID
WORKDIR /app
COPY --from=publish --chown=app:app /app/publish ./
ENTRYPOINT ["./VeriBot"]

CsProj:

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <NeutralLanguage>English</NeutralLanguage>
    <Version>1.0.0</Version>
    <DebugType>portable</DebugType>
    <ImplicitUsings>disable</ImplicitUsings>
    <PackageVersion>1.0.0</PackageVersion>
    <AssemblyVersion>1.0.0</AssemblyVersion>
    <Deterministic>true</Deterministic>
    <LangVersion>latest</LangVersion>
    <TargetFramework>net8.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <PlatformTarget>ARM</PlatformTarget>
    <RuntimeIdentifier>linux-arm</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <DefineConstants />
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="DSharpPlus" Version="4.4.6" />
    <PackageReference Include="DSharpPlus.CommandsNext" Version="4.4.6" />
    <PackageReference Include="DSharpPlus.Interactivity" Version="4.4.6" />
    <PackageReference Include="DSharpPlus.SlashCommands" Version="4.4.6" />
    <PackageReference Include="Humanizer.Core" Version="2.14.1" />
    
    <PackageReference Include="RestSharp" Version="110.2.0" />
    <PackageReference Include="ScottPlot" Version="5.0.21" />
    <PackageReference Include="Serilog" Version="3.1.1" />
    <PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
    
    <PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
    <PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
    <PackageReference Include="SixLabors.ImageSharp.Drawing" Version="2.1.2" />
    <PackageReference Include="Zalgo" Version="0.3.0" />

    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
        <PrivateAssets>all</PrivateAssets>
        <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
    <PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
</ItemGroup>

docker info run on PI:

Client: Docker Engine - Community
 Version:    25.0.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 2
  Running: 1
  Paused: 0
  Stopped: 1
 Images: 2
 Server Version: 25.0.4
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.10.63-v7l+
 Operating System: Raspbian GNU/Linux 10 (buster)
 OSType: linux
 Architecture: armv7l
 CPUs: 4
 Total Memory: 7.714GiB
 Name: JackPi
 ID: 62087b62-36a4-466a-8d23-0a96ef0bb744
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No memory limit support
WARNING: No swap limit support
WARNING: No kernel memory TCP limit support
WARNING: No oom kill disable support

lscpu run on PI:

Architecture:        armv7l
Byte Order:          Little Endian
CPU(s):              4
On-line CPU(s) list: 0-3
Thread(s) per core:  1
Core(s) per socket:  4
Socket(s):           1
Vendor ID:           ARM
Model:               3
Model name:          Cortex-A72
Stepping:            r0p3
CPU max MHz:         1500.0000
CPU min MHz:         600.0000
BogoMIPS:            270.00
Flags:               half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

From logging I've been able to narrow down the crash to this method that is called when starting up the app (it's called in the constructor of its class and the class is registered as a singleton so it is called almost immediately after startup).

Method:

private void LoadGuildData()
{
    _logger.LogInformation("Loading data from database: Guilds");
    using (var db = _dbContextFactory.CreateDbContext())
    {
        _logger.LogInformation("Getting Guild data from database");
        _guildsByDiscordId = db.Guilds.AsNoTracking().ToDictionary(g => g.DiscordId);
        _logger.LogInformation("Getting Guild data from database done");
    }
}

The logs just before the crash indicate it reaches the call to the database but doesn't get past it:

[00:00:00 INF] Logger Created
[00:00:00 DBG] Hosting starting
[00:00:00 INF] Loading data from database: Guilds
[00:00:00 DBG] An 'IServiceProvider' was created for internal use by Entity Framework.
[00:00:00 INF] Getting Guild data from database
Unhandled exception. System.Runtime.InteropServices.COMException (0x8007054F): An internal error occurred.
 (0x8007054F)
   at System.Threading.WaitHandle.WaitOneCore(IntPtr waitHandle, Int32 millisecondsTimeout)
   at System.Threading.WaitHandle.WaitOneNoCheck(Int32 millisecondsTimeout)
   at System.Threading.PortableThreadPool.GateThread.GateThreadStart()
   at System.Threading.Thread.StartCallback()
Fatal error. Internal CLR error. (0x80131506)
   at System.Threading.WaitHandle.WaitOneCore(IntPtr, Int32)
   at System.Threading.WaitHandle.WaitOneNoCheck(Int32)
   at System.Threading.PortableThreadPool+GateThread.GateThreadStart()
   at System.Threading.Thread.StartCallback()

Any help is appreciated I'm not super familiar with the low level details of this kind of stuff so maybe I'm missing something obvious, let me know if you need me to grab any more info that might help diagnose.

0

There are 0 best solutions below