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.74k stars 3.18k forks source link

StackOverflowException after upgrade from 2.0.2 to 2.1.1 #12539

Closed danobri closed 5 years ago

danobri commented 6 years ago

I recently tried upgrading an application from EF Core 2.0.2 to 2.1.1, and following the upgrade, one of the common (and more complicated) projections in the application is throwing a StackOverflowException. I am using Automapper to centralize the code that defines the projections (using the AutoMapper.QueryableExtensions.ProjectTo function), but I believe the issue is with EntityFramework, as it can be resolved by downgrading from EF Core 2.1.1 to 2.0.2. The projection is particularly complicated, doing a bunch of formatting on many columns across numerous joined tables, but it has worked fine prior to the 2.1 release.

System.StackOverflowException
  HResult=0x800703E9
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

Steps to reproduce

I have created a project to reproduce the issue, but it includes a portion of code from a production application, including the database schema and some data that is necessary to reproduce the issue, so am wondering if it would be possible to submit the project privately?

Further technical details

EF Core version: 2.1.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Win x64 IDE: Visual Studio 2017 15.7.4

ajcvickers commented 6 years ago

@danobri Can you send the project to me? I am "avickers" at this place I work--microsoft.com

danobri commented 6 years ago

Great - thanks! On it's way...

danobri commented 6 years ago

@ajcvickers The email is getting blocked due to "executable content." I tried changing the zip file to a txt extension, but that did not work.

ajcvickers commented 6 years ago

@danobri Clean the build to strip out all executables before zipping. There shouldn't need to be any DLLs, etc. in there as everything will be either restored from NuGet or built.

danobri commented 6 years ago

Done - looks like it went through this time - let me know if you got it. You will need to run the SCHEMA script to create the database, and DATA script to seed the database. You may also need to alter the database file locations in the SCHEMA script to work with whatever version you have installed.

danobri commented 6 years ago

Any update on this? I would be open to workarounds, as otherwise I can't upgrade our application until v2.2.0 is RTM at the end of 2018.

danobri commented 6 years ago

Ugh - just saw this got punted to 3.0.0. Would really appreciate it if you could explain why it got pushed all the way to v3, as well as any suggestions you might have for a workaround in the meantime.

ajcvickers commented 6 years ago

Removing milestone to discuss workarounds in triage.

maumar commented 6 years ago

@danobri as a workaround you can split the query into 2, e.g.

namespace EfPerformanceExperiment.Models
{
    public class Fhc2 : Model
    {
        public Option Parent { get; set; }
        public Option Platform { get; set; }
        public Option Cycle { get; set; }
        public Option DisplayPanel { get; set; }
        public Option Processor { get; set; }
        public Option ProcessorActivation { get; set; }
        public Option Memory { get; set; }
        public Option Storage { get; set; }
    }

    public class Fhc : Model
  {
        public Option GraphicsCard { get; set; }
        public Option OpticalDrive { get; set; }
        public Option WirelessLan { get; set; }
        public Option Battery { get; set; }
        public Option PowerSupply { get; set; }
        public Option Chassis { get; set; }
        public Option SourcingCountry { get; set; }

        public string PwaPlatformCode { get; set; }
    public string Notes { get; set; }

    public bool Count { get; set; }

    public bool IsReferenced { get; set; }

    public IEnumerable<FhcFhcRegion> FhcFhcRegion { get; set; }

    public IEnumerable<FhcCycle> FhcCycle { get; set; }

    public IEnumerable<FhcMod> FhcMod { get; set; }
  }

StackOverflow happens because the original query is complex and the query processing got more complicated in 2.1. Currently for 3.0 we plan to do a lot of cleanup/refactoring in the query pipeline which will hopefully simplify the internal processing.

macwier commented 5 years ago

If anyone stumbles around here. Another possible workaround is to increase the stack size (either by using editbin.exe or by targetting x64). Seems like easiest workaround while waiting for EF Core 3.0. In my case, changing from default 1MB to 2MB made the error go away.

sporifolous commented 5 years ago

The workaround unfortunately isn't enough for us in our case. Really disappointing to see such a fundamental issue being punted.

smitpatel commented 5 years ago

@sporifolous - Can you run you code on latest daily build? Similar stackoverflow issue has been fixed in 3.0 release. (See #13392).

maumar commented 5 years ago

I verified this works on current bits, closing