efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Alpine 3.13 image is crashing on dotnet test

Open ChaosEngine opened this issue 5 years ago • 39 comments

Describe the Bug

Running dotnet test on Alpine 3.13 docker based image crashes test runner.

When running on mcr.microsoft.com/dotnet/sdk:5.0-alpine3.12 it succeeds When running on mcr.microsoft.com/dotnet/sdk:5.0-alpine it fails

Steps to Reproduce

Dockerized repro based on https://github.com/dotnet/EntityFramework.Docs (https://github.com/dotnet/EntityFramework.Docs/tree/master/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests specifically)

Start docker sdk alpine image docker run -it --rm mcr.microsoft.com/dotnet/sdk:5.0-alpine

and then. execute this in interactive terminal..

#working project dir
cd /srv/
#I just need proper ll, c'mon
alias ll='ls -lah --color'
#usefull debugging and testing stuff
apk add --update vim strace gdb

#our repo to reproduce
git clone https://github.com/dotnet/EntityFramework.Docs.git

#working dir with tests
cd /srv//EntityFramework.Docs/samples/core/Miscellaneous/Testing/ItemsWebApi/Tests/

#build for restoring packages, simple.
dotnet build
#now tests - this crashes!!!!
dotnet test

#deeper investigation?
#strace dotnet test --logger trx --results-directory _temp -v m --blame-crash
#vim -p _temp/*.trx _temp/*/*.xml

Other Information

The same stuff when run with docker run -it --rm mcr.microsoft.com/dotnet/sdk:5.0-alpine works and just properly fails saying LocalDB is not avaialblre under Linux :-)

Output of docker version

Client:
 Version:           19.03.15
 API version:       1.40
 Go version:        go1.15.7
 Git commit:        420b1d3625
 Built:             Thu Feb  4 20:43:34 2021
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          19.03.15
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.15.7
  Git commit:       420b1d3625
  Built:            Thu Feb  4 20:43:19 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.3.9
  GitCommit:        ea765ab
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683b971d9c3ef73f284f176672c44b448662

Output of docker info

Client:
 Debug Mode: false

Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 40
 Server Version: 19.03.15
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ea765ab
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
 init version: fec3683b971d9c3ef73f284f176672c44b448662
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.4.72-gentoo
 Operating System: Gentoo/Linux
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.29GiB
 Name: chaos2
 ID: OUE5:YKZ7:KCDZ:CTG3:BDT2:KLUH:7BW4:FRYG:47XX:25NZ:F5AL:Y67R
 Docker Root Dir: /mnt/samsung512GB/var/lib/docker
 Debug Mode: false
 Username: chaosengine
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

ChaosEngine avatar Feb 18 '21 17:02 ChaosEngine

I've confirmed it's a segfault crash. It occurs when calling context.Database.EnsureCreated() when using a file-based connection for SQLite. So it seems to be related to Entity Framework or native implementation of SQLite. I saw that the db file does get created on the file system.

I've created a simple repro project that doesn't involve dotnet test. The crux of the repro is here:

using (var context = new ItemsContext(options))
{
  context.Database.EnsureCreated();
}

The call to EnsureCreated is what causes the crash.

Repro steps

  1. Unzip repro.zip to new folder
  2. docker build -t app .
  3. docker run --rm -it app

I've also collected a crash dump: core.zip

mthalman avatar Feb 18 '21 19:02 mthalman

Moving to efcore repo for further investigation.

mthalman avatar Feb 18 '21 19:02 mthalman

@ericsink @bricelam Is SQLite expected to work on Alpine Linux?

ajcvickers avatar Feb 19 '21 17:02 ajcvickers

Yes, it is supposed to work on Alpine linux. It seems like it breaks 1-2 times per year, usually due to something in the environment changing, IIRC.

ericsink avatar Feb 19 '21 17:02 ericsink

@ericsink Is there anything we can do help understand the issue on Alpine? I don't think there is anything we can change on our end, unless I'm missing something.

ajcvickers avatar Mar 01 '21 16:03 ajcvickers

Based on what I saw above, it looks like everything succeeded with Alpine docker image 3.12 and then failed with 3.13. So I had been assuming something changed in between that caused the break.

One possibility I have not investigated yet is that maybe "the thing that changed" would require me to build the alpine sqlite library differently, such as, for example, with a more recent compiler or C lib, etc.

I'll try the repro above and see if it yields any clues.

ericsink avatar Mar 01 '21 17:03 ericsink

Thanks @ericsink

ajcvickers avatar Mar 01 '21 17:03 ajcvickers

I tried the repro.zip above and it didn't fail. On the possibility that I did something wrong, one of my coworkers tried it, and no crash for them either.

Still quite possible we're doing the repro incorrectly somehow.

Can someone point me to a list of things that changed in the docker image between 3.12 and 3.13 ?

ericsink avatar Mar 01 '21 18:03 ericsink

I tried the repro.zip above and it didn't fail. On the possibility that I did something wrong, one of my coworkers tried it, and no crash for them either.

Did it successfully output created in the console? If not, then it crashed.

mthalman avatar Mar 01 '21 18:03 mthalman

Ah, I see. No, it did not output created.

ericsink avatar Mar 01 '21 18:03 ericsink

Not sure, but perhaps something in #14504 would be helpful here.

ericsink avatar Mar 01 '21 19:03 ericsink

I tried the repro.zip above and it didn't fail. On the possibility that I did something wrong, one of my coworkers tried it, and no crash for them either.

Still quite possible we're doing the repro incorrectly somehow.

Can someone point me to a list of things that changed in the docker image between 3.12 and 3.13 ?

Sure thing, I went this path also, and found this comparison: https://pkgs.alpinelinux.org/packages?name=sqlite&branch=v3.13 vs https://pkgs.alpinelinux.org/packages?name=sqlite&branch=v3.12

ChaosEngine avatar Mar 01 '21 19:03 ChaosEngine

Oh. I didn't realize the 3.12 and 3.13 referred to versions numbers of Alpine Linux itself.

@ChaosEngine FWIW, the links you gave appear to refer to Alpine's sqlite package, which is probably not involved here, but I cannot say for certain. The most likely case here is that my e_sqlite3 build for linux/musl/alpine is somehow incompatible with 3.13.

ericsink avatar Mar 01 '21 19:03 ericsink

More info, in case it helps anyone recognize a problem:

My e_sqlite3 builds for alpine have always been built on a regular ubuntu system using the package musl-dev. The actual command I use to build is musl-gcc.

eric@LAPTOP-6A6HQVJ9:/mnt/c/Users/eric/dev/cb/bld$ musl-gcc --version
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609

My current version of ubuntu for this build is 16.04 xenial.

My current version of the musl-dev package is 1.1.9-1. apt update does not indicate an available upgrade for this package.

A current question is whether this build configuration results in things that are compatible with alpine 3.12 but not with alpine 3.13.

ericsink avatar Mar 01 '21 20:03 ericsink

My current version of the musl-dev package is 1.1.9-1. apt update does not indicate an available upgrade for this package.

A current question is whether this build configuration results in things that are compatible with alpine 3.12 but not with alpine 3.13.

Alpine 3.13 was upgraded to musl 1.2 and also had some changes around time64. I wonder if either of those two things are related. See the Alpine 3.13 release notes.

mthalman avatar Mar 01 '21 20:03 mthalman

FWIW, my alpine3.13 dotnet-dump core dump analysis gave me those unmanaged suspects (based on repro.zip):

> clrstack
OS Thread Id: 0x374 (0)
        Child SP               IP Call Site
00007FFE38176CF0 000000000000e5c6 [InlinedCallFrame: 00007ffe38176cf0]
00007FFE38176CF0 00007fab608d71e0 [InlinedCallFrame: 00007ffe38176cf0]
00007FFE38176CE0 00007FAB608D71E0 <unknown method>
00007FFE38176D80 00007FAB60BDAE8C /srv/app/bin/Debug/net5.0/SQLitePCLRaw.provider.dynamic_cdecl.dll!Unknown
00007FFE38176DB0 00007FAB60BD95C4 /srv/app/bin/Debug/net5.0/Microsoft.Data.Sqlite.dll!Unknown
00007FFE38176DF0 00007FAB60BD9159 /srv/app/bin/Debug/net5.0/Microsoft.Data.Sqlite.dll!Unknown
00007FFE38176EF0 00007FAB60BD8D71 /srv/app/bin/Debug/net5.0/Microsoft.Data.Sqlite.dll!Unknown
00007FFE38176F10 00007FAB60BD8CFB /srv/app/bin/Debug/net5.0/Microsoft.Data.Sqlite.dll!Unknown
00007FFE38176F70 00007FAB60BD55E5 /srv/app/bin/Debug/net5.0/Microsoft.EntityFrameworkCore.Relational.dll!Unknown
00007FFE381770D0 00007FAB60BD322E /srv/app/bin/Debug/net5.0/Microsoft.EntityFrameworkCore.Sqlite.dll!Unknown
00007FFE38177170 00007FAB608C4848 /srv/app/bin/Debug/net5.0/Microsoft.EntityFrameworkCore.Relational.dll!Unknown
00007FFE381771B0 00007FAB603E052D /srv/app/bin/Debug/net5.0/Microsoft.EntityFrameworkCore.dll!Unknown
00007FFE381771E0 00007FAB5F436877 /srv/app/bin/Debug/net5.0/app.dll!Unknown

ChaosEngine avatar Mar 01 '21 21:03 ChaosEngine

Also I've observed following when playing with vanilla libsqlite:

/srv/app # apk add sqlite-dev
/srv/app # cd /srv/app
/srv/app # dotnet build
Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /srv/app/app.csproj (in 618 ms).
  app -> /srv/app/bin/Debug/net5.0/app.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

/srv/app # /srv/app/bin/Debug/net5.0/app
Segmentation fault (core dumped)

/srv/app # cp /usr/lib/libsqlite3.so.0.8.6  /srv/app/bin/Debug/net5.0/runtimes/linux-x64/native/libe_sqlite3.so

/srv/app # /srv/app/bin/Debug/net5.0/app
created

Looks like when installed original libsqlite3 (musl compiled and alpine-3.13 build) and overwriting dotnet build linux-x64 native version of sqlite - the problem is gone, otherwise it is very reproducible.

ChaosEngine avatar Mar 02 '21 08:03 ChaosEngine

I'm going to try and get setup to build an e_sqlite3 actually under alpine 3.13.

ericsink avatar Mar 02 '21 16:03 ericsink

OK, I haven't gotten anywhere on this.

I have no experience with alpine linux, and very little experience with docker. I want to learn these things, but having my education in the critical path of this issue may not be a good idea.

I assume that if I just build sqlite on alpine 3.13 the resulting library would work.

Anybody want to give me just enough docker knowledge to run gcc under alpine 3.13 ?

I have wsl 2 installed, which I use regularly, but I don't see a wsl image for alpine 3.13 yet.

Feel free to just tell me to go back and do my homework, but if you want to move this bug along, telling me exactly what commands to type would probably do that. :-)

ericsink avatar Mar 11 '21 16:03 ericsink

You could try these instructions to upgrade your WSL Alpine installation to 3.13. And here are instructions for for installing gcc on Alpine.

mthalman avatar Mar 11 '21 20:03 mthalman