Queries with EF Core causes 'Cannot continue the execution because the session is in the kill state'

Arthur Menétrey 0 Reputation points
2024-06-07T10:02:04.1466667+00:00

Some EF Core queries are throwing the following error in our code :

Cannot continue the execution because the session is in the kill state. Une erreur grave s'est produite pendant la commande actuelle. Les résultats devront être supprimés, le cas échéant.

These errors are really hard to debug beacause they only appear in the production environment.

The weird thing is that changing a small portion of the query will fix the issue for some times before it appears again. Let me explain with the following query :

This query was working last week but not anymore :

long planningGroupId = 0; // It's a method parameter in my code
using var db = myDbContextFactory.Create();
var result = await db.Plannings.Where(o => o.PlanningGroupId == planningGroupId && !o.Deleted)
.Select(p => new Tuple<char,long>(p.RessourceCode, p.RessourceId))
.ToListAsync(cancellationToken);

This query was not working anymore last week but now works :

long planningGroupId = 0; // It's a method parameter in my code
using var db = myDbContextFactory.Create();
var result = await db.Plannings.Where(o => o.PlanningGroupId == planningGroupId && !o.Deleted)
.Select(p => new {ressourceCode = p.RessourceCode, ressourceID = p.RessourceId})
.ToListAsync(cancellationToken);

It is like if the queries have a lifespan and would break for some reasons after sometimes.

It can be fixed temporarily by simply adding a distinct clause or adding a field in the tuple / anonymous type

If you wonder, the EF Core generated queries are working properly on both the production and dev environment :

SELECT [p].[ressource], [p].[ressource_id] FROM [planning] AS [p] WHERE [p].[planning_group_id] = @__planningGroupId_0 AND [p].[deleted] = CAST(0 AS bit)

An error message also appears in the SQL Server logs :

SqlDumpExceptionHandler : Process 597 generated fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is terminating this process.

Our version of SQL Server is up to date as well as the EF Core library. We are currently using .Net 7

Has anyone encountered this bug?

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
710 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,067 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,479 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Erland Sommarskog 103.5K Reputation points MVP
    2024-06-07T21:28:42.8333333+00:00

    Your version is not up to date. An access violation like this is typically the token of a bug in SQL Server. You should download and install the most recent Cumulative Update.

    If you are hitting a known issue, installing the CU will solve your problem. If the issue persists after installing the CU, you should open a support case.

    0 comments No comments