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?