Closed flyfire-cn closed 11 months ago
The ABP project template I used (.netcore) https://aspnetboilerplate.com Sqlite is integrated as follows https://aspnetboilerplate.com/Pages/Documents/EF-Core-Sqlite-Integration
It's working fine.
Click on this article https://docs.microsoft.com/zh-cn/ef/core/modeling/spatial
Installation of the Microsoft. EntityFrameworkCore. Sqlite Microsoft.EntityFrameworkCore.Sqlite.Net TopologySuite
Public static void Configure(DbContextOptionsBuilder builder, DbConnection connection)
{
Builder. UseSqlite (connection, b = >
{
b.UseNetTopologySuite ();
});
}
Run the project, 30 minutes or so, crash.
@flyfire-cn Can you please post a small, runnable, project/solution that demonstrates this crash so that we can investigate.
@flyfire-cn Can you please post a small, runnable, project/solution that demonstrates this crash so that we can investigate.
I created a template project。 It works well in Linux (ubuntu16.04 for Arm64+.netcore2.2SDK + libsqlite3-mod-spatialite) environment. Error in Windows x64 environment.
@ajcvickers
And I found another problem.
Once again, this test project, if released as a framework dependency, will run successfully on my linux-arm64 system.
However, if released in a standalone fashion
Dotnet publish-r linux-arm64-c Release
Display the following error message, I do not know why.
root@NanoPi-NEO2:~# cd /home/pi/spatialite
root@NanoPi-NEO2:/home/pi/spatialite# cd publish
root@NanoPi-NEO2:/home/pi/spatialite/publish# ./flyfire.IMS.Web.Host
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Application startup exception: System.InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.First[TSource](IEnumerable1 source, Func
2 predicate)
at Microsoft.EntityFrameworkCore.Infrastructure.SpatialiteLoader.FindExtension()
at Microsoft.EntityFrameworkCore.Infrastructure.SpatialiteLoader.Load(DbConnection connection)
at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.LoadSpatialite()
at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable
1.Enumerator.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at lambda_method(Closure ) at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable
1.GetEnumerator()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable1 results, QueryContext queryContext, IList
1 entityTrackingInfos, IList1 entityAccessors)+MoveNext() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor
1.EnumeratorExceptionInterceptor.MoveNext()
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.First[TSource](IEnumerable
1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>cDisplayClass15_11.<CompileQueryCore>b__0(QueryContext qc) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source, Expression1 predicate) at flyfire.IMS.EntityFrameworkCore.Seed.Host.DefaultEditionCreator.CreateEditions() in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\Host\DefaultEditionCreator.cs:line 25 at flyfire.IMS.EntityFrameworkCore.Seed.Host.InitialHostDbBuilder.Create() in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\Host\InitialHostDbBuilder.cs:line 14 at flyfire.IMS.EntityFrameworkCore.Seed.SeedHelper.SeedHostDb(IMSDbContext context) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\SeedHelper.cs:line 25 at flyfire.IMS.EntityFrameworkCore.Seed.SeedHelper.WithDbContext[TDbContext](IIocResolver iocResolver, Action
1 contextAction) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\SeedHelper.cs:line 41
at System.Collections.Generic.List1.ForEach(Action
1 action)
at Abp.AbpBootstrapper.Initialize()
at Abp.AspNetCore.AbpApplicationBuilderExtensions.InitializeAbp(IApplicationBuilder app)
at Abp.AspNetCore.AbpApplicationBuilderExtensions.UseAbp(IApplicationBuilder app, Action1 optionsAction) at flyfire.IMS.Web.Host.Startup.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.Web.Host\Startup\Startup.cs:line 103 --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6] Application startup exception System.InvalidOperationException: Sequence contains no matching element at System.Linq.Enumerable.First[TSource](IEnumerable
1 source, Func2 predicate) at Microsoft.EntityFrameworkCore.Infrastructure.SpatialiteLoader.FindExtension() at Microsoft.EntityFrameworkCore.Infrastructure.SpatialiteLoader.Load(DbConnection connection) at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.LoadSpatialite() at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.Open(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable
1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext() at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable
1 source, Boolean& found)
at lambda_method(Closure )
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable1.GetEnumerator() at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable
1 results, QueryContext queryContext, IList1 entityTrackingInfos, IList
1 entityAccessors)+MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext() at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable
1 source, Boolean& found)
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>cDisplayClass15_11.<CompileQueryCore>b__0(QueryContext qc) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source, Expression1 predicate) at flyfire.IMS.EntityFrameworkCore.Seed.Host.DefaultEditionCreator.CreateEditions() in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\Host\DefaultEditionCreator.cs:line 25 at flyfire.IMS.EntityFrameworkCore.Seed.Host.InitialHostDbBuilder.Create() in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\Host\InitialHostDbBuilder.cs:line 14 at flyfire.IMS.EntityFrameworkCore.Seed.SeedHelper.SeedHostDb(IMSDbContext context) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\SeedHelper.cs:line 25 at flyfire.IMS.EntityFrameworkCore.Seed.SeedHelper.WithDbContext[TDbContext](IIocResolver iocResolver, Action
1 contextAction) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.EntityFrameworkCore\EntityFrameworkCore\Seed\SeedHelper.cs:line 41
at System.Collections.Generic.List1.ForEach(Action
1 action)
at Abp.AbpBootstrapper.Initialize()
at Abp.AspNetCore.AbpApplicationBuilderExtensions.InitializeAbp(IApplicationBuilder app)
at Abp.AspNetCore.AbpApplicationBuilderExtensions.UseAbp(IApplicationBuilder app, Action`1 optionsAction)
at flyfire.IMS.Web.Host.Startup.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in D:\codeManager\github.com\aspnet-core-abp-sqlite\src\flyfire.IMS.Web.Host\Startup\Startup.cs:line 103
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
@flyfire-cn I downloaded and built the test app, but I haven'e been able to induce it to crash. Can you provide any more specific instructions for reproducing the crash?
publish this app is test run. cd %~dp0 dotnet ./flyfire.ims.web.host.dll it is crash. @ajcvickers
@flyfire-cn Sorry, but I can't get this to crash. Would it be possible for you to try to isolate the problem a bit more? Attempting to debug an entire application is a bit more than I have the resources for.
@flyfire-cn Sorry, but I can't get this to crash. Would it be possible for you to try to isolate the problem a bit more? Attempting to debug an entire application is a bit more than I have the resources for.
I added two release processing files to the solution publish_win-x64.bat publish_linux-arm64.bat They are under the flyfire.ims.web.host project Run them to generate the corresponding publish file (you need to set flyfire.ims.web.host as the startup project) Run run.bat(win) or run.sh(Linux) in the distribution folder The exception.
Run the project directly under VS2017. It will take a long time for the exception to occur.About 30 minutes.
@ajcvickers
@flyfire-cn I managed to run the project and left it running for some time. It did not crash for me.
@flyfire-cn I managed to run the project and left it running for some time. It did not crash for me.
dotnet core sdk version: 2.2.101
system : windows 10 pro 1803/17134.590
I reproduce the problem,the problem he said exists, and the steps to reproduce it are as follows:
dotnet publish-c release-r win-x64-o publish
.cd publish
.\flyfire.IMS.Web.Host.exe
.Follow these steps and problems will appear.
I reproduce the problem,the problem he said exists, and the steps to reproduce it are as follows:
My operating environment: Dotnet core SDK version: 2.2.103
@ajcvickers Has there been any progress on this issue recently?
@flyfire-cn I will investigate again when I get time. I'm not considering a high priority right now since I have tried and failed to reproduce this issue multiple times, and the repro code is a long way from minimal.
I also had the same issue, with the program crashing after using the spatialite database for a while. If I didn't access it at all the program kept running, but as soon as I read from it constantly it crashes within a minute without any useful debug information or helpful exceptions.
I already used spatialite before it was supported by the EntityFramework and I found a workaround which lets me use the EF Core support, but still use my previous spatialite binaries. I have no idea why my workaround even works, but you know: Never touch a running system! ;)
So my workaround to use my previous working spatialite dll is the following:
public static void UseSpatialite(this DbContextOptionsBuilder optionsBuilder, string connectionString)
{
var connection = new SqliteConnection(connectionString);
UseSpatialite(optionsBuilder, connection);
}
public static void UseSpatialite(this DbContextOptionsBuilder optionsBuilder, DbConnection connection)
{
void OnStateChanged(object sender, StateChangeEventArgs e)
{
if (e.CurrentState != ConnectionState.Open)
return;
if (sender is SqliteConnection senderConnection)
{
senderConnection.EnableExtensions(true);
using (var command = senderConnection.CreateCommand())
{
command.CommandText = "SELECT load_extension('mod_spatialite')";
command.ExecuteNonQuery();
}
senderConnection.EnableExtensions(false);
}
}
connection.StateChange += OnStateChanged;
optionsBuilder.UseSqlite(connection, opts => opts.UseNetTopologySuite());
}
So I just give the EntityFramework a DbConnection and handle connecting to the db myself. By the way, this is also how I used Spatialite before EF Core 2.2.
I spend quite some time until I managed to get working spatialite binaries for windows. So in case someone want's to try them too, here they are: Spatialite.zip
PS: In my case I wasn't even using .Net Core since it is a WPF application. I used .net framework 4.6.1.
@faryu
I found a workaround which lets me use the EF Core support, but still use my previous spatialite binaries.
So you haven't seen this crash when using the older binaries with EF Core? Which version are the older binaries?
I'm using mod_spatialite-4.3.0a. This post solved it for me.
I used a already build binary of the mod_spatialite dll with it's dependencies (build at 18.01.2018) and then I replaced the libstdc++_64-6.dll and libgcc_s_seh-1.dll file (the hint being from the linked post) with the dll from mingw64 (version x86_64-8.1.0-release-win32-seh-rt_v6-rev0).
I never had a problem caused by the database since then.
I have the same issue. For me, dotnet crashes when the processes's memory builds up. The memory build up seems to be caused by yet to be garbage collected objects that were returned from spatial queries. Looking in the task manager, dotnet starts at about 170MB and I can get it crash every time when the memory goes up to around 230MB.
I am using EF 2.2.0 and my application is running on Windows 10.
This is the log from the Event Viewer:
Faulting application name: dotnet.exe, version: 3.0.19.46305, time stamp: 0x5d7bb03a Faulting module name: libwinpthread-1.dll, version: 1.0.0.0, time stamp: 0x00000000 Exception code: 0x40000015 Fault offset: 0x0000000000008dc5 Faulting process id: 0x51c8 Faulting application start time: 0x01d59c07d9fa5a1c Faulting application path: C:\Program Files\dotnet\dotnet.exe Faulting module path: C:\Users{app path}\libwinpthread-1.dll Report Id: f3c36362-76e4-4bde-9f34-80e88553af8f Faulting package full name: Faulting package-relative application ID:
Unfortunately I don't have much more information.
The "Sequence contains no matching element" error in self-contained deployments was fix in EF Core 3.1 (issue #14093)
I've taken a new build of SpatiaLite. Can anyone confirm whether the memory leak and crash are fixed? (add the following to your *.csproj file)
<ItemGroup>
<PackageReference Include="mod_spatialite" Version="4.3.0.100-rc1" />
</ItemGroup>
Unfortunately, the program still crashes and I get the same error with mod_spatialite 4.3.0.100-rc1:
Faulting application name: dotnet.exe, version: 3.0.19.46305, time stamp: 0x5d7bb03a Faulting module name: libwinpthread-1.dll, version: 1.0.0.0, time stamp: 0x00000000 Exception code: 0x40000015 Fault offset: 0x0000000000008e85 Faulting process id: 0x2510 Faulting application start time: 0x01d5cbf0cdfb894c Faulting application path: C:\Program Files\dotnet\dotnet.exe Faulting module path: C:\Users{appPath}\libwinpthread-1.dll Report Id: 84ac7ff9-f786-4144-849e-a82e28322f41 Faulting package full name: Faulting package-relative application ID:
Note from team discussion: we are closing this issue because we have repeatedly not been able to reproduce it. We would be happy to reopen and investigate more if we can get a project that reproduces this behavior.
Note from team discussion: we are closing this issue because we have repeatedly not been able to reproduce it. We would be happy to reopen and investigate more if we can get a project that reproduces this behavior.
Can you try this project?
@clarkgranum Did you reference the new build in your project? If so, can you point to where?
@clarkgranum Did you reference the new build in your project? If so, can you point to where?
The new build of mod_spatialite (4.3.0.100-rc1)? I did not reference this in the linked project, but I can try again. I did try this new build in a different project and it still crashed for me.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.
Can you please re-open this issue? I am able to trigger a crash within a minute after starting an asp.net core app by repeating a very simple query. I have new code below, which includes the reference to the updated mod_spatialite build. I realized the previous repository I referenced did not load properly in Visual Studio when cloned. Just clone the repository below and start the application from Visual studio (no other setup should be required):
https://github.com/clarkgranum/ef_core_spatialite_issue_14561
@bricelam I am able to reproduce this. I get a hard crash after about 157 iterations, with exit code 3. When run in the debugger it crashes the entire process. I don't get stack traces or other information.
The crash goes away if I remove the call to UseNetTopologySuite
but make no other changes.
@bricelam I am able to reproduce this. I get a hard crash after about 157 iterations, with exit code 3. When run in the debugger it crashes the entire process. I don't get stack traces or other information.
The crash goes away if I remove the call to
UseNetTopologySuite
but make no other changes.
I get the same exact results, except for the number of iterations it takes to crash the program (usually 100-150 for me). Thank you for looking into this.
Ouch, sounds like we need to do some native debugging to understand where the problem is. Possibilities:
I can reproduce this same exact issue easily. Attached a simple tiny sample that reproduces the killing of app after 530'ish SQLite reads. Could you please take a look at it one more time. Really need a fix. TestNetTopologySuite.zip attempts.
@AndriySvyryd are you able to reproduce this crash on your end?
Yes, we can reproduce it, but it's not clear yet whether this is something we can fix.
Are there any good suggestions for workaround while you are looking for a fix?
I've taken a new build of SpatiaLite. Can anyone confirm whether the memory leak and crash are fixed? (add the following to your *.csproj file)
<ItemGroup> <PackageReference Include="mod_spatialite" Version="4.3.0.100-rc1" /> </ItemGroup>
Just ran into the problem myself, upgraded the mod_spatialite package to this version fixed the problem for me. No more crash.
i tried adding the above package reference
I've taken a new build of SpatiaLite. Can anyone confirm whether the memory leak and crash are fixed? (add the following to your *.csproj file)
<ItemGroup> <PackageReference Include="mod_spatialite" Version="4.3.0.100-rc1" /> </ItemGroup>
Just ran into the problem myself, upgraded the mod_spatialite package to this version fixed the problem for me. No more crash.
I test tested the PackageReference and it worked for me. Thank you for putting it together
@kabuchanga can you try my sample app to see if it crashes for you. I added
<ItemGroup>
<PackageReference Include="mod_spatialite" Version="4.3.0.100-rc1" />
</ItemGroup>
to my sample app. So now instead of crashing at around 530 iterations it crashes at around 1060 iterations. TestNetTopologySuite.zip
@d79ima I tested your sample, and reproduce the crash around 1060 too. But for me this reproduction is missing the dispose on the connection, if you add a dispose after the close the crash doesn't happen anymore. I think an explicit dispose is needed here because of the native code nature of the mod_spatialite library. So if you manually handle connections you will have to ensure that they are disposed or implement some sort of pool mecanism to reuse them.
@kvpt you are quite right. I modified my test sample slightly to match what my needs actually are. I have an application that needs to work with lots of different sqlite database files over time. So the sample app now creates a unique sqlite file for each iteration of the loop. The program crashes after around 366 iterations with the mod_spatialite Package reference, and after around 176 without. TestNetTopologySuite.zip
@d79ima I confirm the crash but it's at 355 for me, not sure what cause the difference but yes the issue is present. I tried to use a more recent EfCore version and runtime and the error is now different. The program not display a different message and doesn't shutdown. This is strange, because it seems to indicate the the connections doesn't close but some command seems to pass, so some are still available. Adding a delay doesn't seems to solve the issue, so the leak seems persistent. I'm not sure that it's the same issue as the one described in this thread as the behavior is not the same, the original issue seems to have been resolved by the package update. So I advise you to open a new issue, and it will better expose the issue to the efcore dev team.
No longer repros with 8.0 and latest Spatialite:
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.NetTopologySuite" Version="8.0.0" />
<PackageReference Include="mod_spatialite" Version="4.3.0.1" />
downloaded .net 8 sdk and updated the above sample app TestNetTopologySuite.zip to target .net 8 and NetTopologySuite 8.0.0. Using mod_spatialite 4.3.0.1. Now as it runs i start seeing a new error: "Error too many connections max 64", and the application still crashes out at around 640 databases created.
Now if i switch to mod_spatialite 4.3.0.100-rc1, then the sample app still preints the max 64 connections error but seems to keep going forever, which is good. Is this "max 64 connections" error harmless? It does not seem to prevent the app from doing what it needs to do...
@d79ima That crash being tracked by this issue no longer occurs with the repro code provided. If there is a different problem, then I think that would better be tracked by a new issue with a complete repro for the new problem.
I used it in the project Microsoft. EntityFrameworkCore. Sqlite It works
Installation of the Microsoft.EntityFrameworkCore.Sqlite.Net TopologySuite After that, Run the program, do nothing, about twenty to forty minutes or so, the program crashes.
Exception message: Stack trace:Application Error
Steps to reproduce