dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.73k stars 3.18k forks source link

Linux Segmentation fault - Running on either runtime:2.2 or runtime:3.0 Docker image #18068

Closed michaeldtaylor closed 2 years ago

michaeldtaylor commented 5 years ago

I have followed the Spatial Data - EF Core (https://docs.microsoft.com/en-us/ef/core/modeling/spatial) instructions to the letter, and the example works perfectly on Windows.

When creating and running on a .NET Core 2.2/3.0 Linux Docker image:

mcr.microsoft.com/dotnet/core/runtime:2.2
mcr.microsoft.com/dotnet/core/runtime:3.0

which has also has:

RUN apt-get update
RUN apt-get --yes --force-yes install libsqlite3-mod-spatialite

Added to the Dockerfile I get:

Info Infrastructure: Entity Framework Core 2.2.6-servicing-10079 initialized 'AbCoreDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: MigrationsHistoryTable=os.migrations LoadSpatialite using NetTopologySuite
Info Command: Executed DbCommand (32ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
PRAGMA foreign_keys=ON;
./entrypoint.sh: line 2:     8 Segmentation fault      dotnet CounterApp.dll

The version of libsqlite3-mod-spatialite that gets installed by apt-get is:

lrwxrwxrwx  1 root root       23 Feb  5  2016 mod_spatialite.so -> mod_spatialite.so.7.1.0
lrwxrwxrwx  1 root root       23 Feb  5  2016 mod_spatialite.so.7 -> mod_spatialite.so.7.1.0
-rw-r--r--  1 root root  5879944 Feb  5  2016 mod_spatialite.so.7.1.0

in the folder:

/usr/lib/x86_64-linux-gnu

Any ideas? I need to be able to generate a SpatiaLite database on a Linux Docker instance.

Steps to reproduce

Dockerfile (final steps only):

FROM mcr.microsoft.com/dotnet/core/runtime:3.0
WORKDIR /app

# Build a shell script because the ENTRYPOINT command doesn't like using ARG
RUN echo "#!/bin/bash\ndotnet ${project_name}.dll" > /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Install mod_spatialite and dependencies
RUN apt-get update
RUN apt-get --yes --allow-change-held-packages install libsqlite3-mod-spatialite

COPY --from=builder /sln/dist .
ENTRYPOINT ["./entrypoint.sh"]

Program.cs

// Configure EF Core
services.AddDbContext<AbCoreDbContext>(c => c
    .UseSqlite(connectionString, o => o
        .MigrationsHistoryTable("migrations")
        .UseNetTopologySuite()));

PackageReferences:

  <ItemGroup>
    <PackageReference Include="Lamar" Version="3.1.0" />
    <PackageReference Include="Lamar.Microsoft.DependencyInjection" Version="3.2.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="3.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.0.0" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.0.0" />
    <PackageReference Include="NetTopologySuite.Core" Version="1.15.3" />
    <PackageReference Include="NLog" Version="4.6.7" />
    <PackageReference Include="NLog.Extensions.Logging" Version="1.5.4" />
  </ItemGroup>

Further technical details

EF Core version: 2.2.6 (and 3.0.0) Database provider: Microsoft.EntityFrameworkCore.Sqlite Target framework: .NET Core 2.2 (and 3.0) Operating system: Linux (debian.9-x64) IDE: Visual Studio 2019 16.3.1

michaeldtaylor commented 5 years ago

I just tried: mcr.microsoft.com/dotnet/core/runtime:3.0-bionic, to see if Ubuntu 18 was any better. If I take the SpatiaLiteLoader out into my own app I can get loading the module by explicitly setting the environment variable:

DYLD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/

and doing:

SELECT load_extension('mod_spatialite.so')

smitpatel commented 5 years ago

@bricelam to find dupe.

bricelam commented 5 years ago

Duplicate of #16667

michaeldtaylor commented 5 years ago

How is this a “duplicate”. This is Debian Linux - not Mac OS. Your solution from that issue certainly isn’t relevant. Is this just fundamentally broken on anything but Windows?

bricelam commented 5 years ago

I think it’s an issue with the latest version of PROJ, but I haven’t been able to pin it down

bricelam commented 5 years ago

I’m experimenting with building a more minimal version of SpatiaLite that doesn’t reference PROJ. I’m thinking about including Linux and macOS (and maybe iOS and Android) binaries in the NuGet package.

michaeldtaylor commented 5 years ago

Ok thanks for the clarification. It would be good if the bins could be included and it “just worked”. As I say apt-get version seems broken on Debian 9, but works on Ubuntu 18. You have to love C extensions! Loading a known working version on all Linux distros would be good.

bricelam commented 5 years ago

+1 I’m working on including binaries for more platforms over in bricelam/mod_spatialite-NuGet