GithubHelp home page GithubHelp logo

Comments (4)

AppSecSeanner avatar AppSecSeanner commented on August 25, 2024 1

Upgrading the .Net version from 4.5.2 to 4.6.1 in our production environment solved our intermittent IIS app pool crashing issues.

from ef6.

divega avatar divega commented on August 25, 2024

@sglencross can you provide the LINQ query?

Also, can you try setting context.Configuration.UseDatabaseNullSemantics = true before that particular query? We have had previous reports that the default (UseDatabaseNullSemantics = false) can cause larger trees that in a very complicated query can cause stack overflow.

from ef6.

AppSecSeanner avatar AppSecSeanner commented on August 25, 2024

Setting this before our query is problematic as we have abstracted our context from the linq operations on the DBSet. The query related to the stack overflow above is spread out across several classes and would be difficult to summarize without changing its behaviour.

We do have a simpler query not related to the stack dump above but has also intermittently crashed our IIS app pool. We suspect it is also having the same kind of issue.

//_dbTerms is a IDbSet<Term> exposed on the context
public IEnumerable<TermModel> Execute(int languageId, Guid clientId)
{
    var clientSpecificTerms = _dbTerms.Where(t => t.ClientId == clientId && t.LanguageId == languageId);

    var languageFallbackTerms = _dbTerms.Where(t => t.ClientId == null && t.LanguageId == languageId &&
                                                                    clientSpecificTerms.All(clientTerm => clientTerm.Key != t.Key));

    var clientDefaultTerms = _dbTerms.Where(t => t.ClientId == clientId && t.LanguageId == Languages.English.Id &&
                                                                clientSpecificTerms.All(clientTerm => clientTerm.Key != t.Key) &&
                                                                languageFallbackTerms.All(languageFallback => languageFallback.Key != t.Key));

    var defaultTerms = _dbTerms.Where(t => t.LanguageId == Languages.English.Id && t.ClientId == null &&
                                                            clientSpecificTerms.All(clientTerm => clientTerm.Key != t.Key) &&
                                                            languageFallbackTerms.All(languageFallback => languageFallback.Key != t.Key) &&
                                                            clientDefaultTerms.All(clientDefaultTerm => clientDefaultTerm.Key != t.Key));

    return clientSpecificTerms.Union(languageFallbackTerms)
                              .Union(clientDefaultTerms)
                              .Union(defaultTerms)
                              .OrderBy(t => t.Key)
                              .Select(t => new TermModel { Key = t.Key, Value = t.Value })
                              .ToList();
}

This is the generated SQL

SELECT 1 AS [C1], [Project2].[Key] AS[Key], [Limit1].[Value] AS[Value] FROM 
    (SELECT[Distinct1].[Key] AS[Key]FROM ( SELECT DISTINCT[Extent1].[Key] AS[Key] FROM[dbo].[Terms] AS[Extent1] 
            WHERE([Extent1].[LanguageId] IN(@languageId,1)) 
            AND([Extent1].[ClientId] = @clientId OR[Extent1].[ClientId] IS NULL) 
        ) AS[Distinct1] 
    ) AS [Project2] 
    OUTER APPLY (SELECT TOP (1) [Project3].[Value] AS [Value] FROM 
        (SELECT CASE WHEN([Extent2].[LanguageId] = @languageId) THEN cast(1 as bit) WHEN([Extent2].[LanguageId] <> @languageId) THEN cast(0 as bit) END AS[C1], 
                CASE WHEN([Extent2].[ClientId] = @clientId) THEN cast(1 as bit) WHEN(NOT(([Extent2].[ClientId] = @clientId) AND((CASE WHEN([Extent2].[ClientId] IS NULL) THEN cast(1 as bit) ELSE cast(0 as bit) END) = 0))) THEN cast(0 as bit) END AS[C2], [Extent2].[Value] AS[Value] 
            FROM[dbo].[Terms] AS[Extent2] 
            WHERE ([Extent2].[LanguageId] IN (@languageId,1)) 
            AND ([Extent2].[ClientId] = @clientId OR[Extent2].[ClientId] IS NULL) 
            AND (([Project2].[Key] = [Extent2].[Key]) OR(([Project2].[Key] IS NULL) 
            AND ([Extent2].[Key] IS NULL))) 
    ) AS [Project3] 
    ORDER BY [Project3].[C1] DESC, [Project3].[C2] DESC) AS[Limit1]

Would changing the UseDatabaseNullSemantics setting on this query prevent the intermittent crashes happening with this query?

from ef6.

AppSecSeanner avatar AppSecSeanner commented on August 25, 2024

We are currently on .Net 4.5.2 and have been informed that there is a known issue that may be contributing to our crashes. Specifically the CLR issue addressed in this hotfix:
https://support.microsoft.com/en-us/kb/3139544#bookmark-issuesresolve
We are going to move to .Net 4.6.1 in the next week or two which will hopefully solve our issue.

from ef6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.