YOXT
YOXT
CC#
Created by YOXT on 11/4/2023 in #help
❔ updating row sometimes times out EF core 7
this has been confusing me lately, i was going thru my logs and i noticed sometimes my endpoint returns a 500. I have looked thru the logs and found the query which is causing it.
await _dbContext.Servers.Where(s => s.Id == id).ExecuteUpdateAsync(s => s.SetProperty(e => e.HitsReceived, e => e.HitsReceived + 1), cancellationToken: cancellationToken);
await _dbContext.Servers.Where(s => s.Id == id).ExecuteUpdateAsync(s => s.SetProperty(e => e.HitsReceived, e => e.HitsReceived + 1), cancellationToken: cancellationToken);
its not every time but sometimes. the reason why I use this EF Linq query is because the servers rows get hit sometimes at the same time and the hitsReceived needs to be thread safe (locking). this is an error from serilog
{
"Timestamp": "2023-11-02T22:08:57.6615548+00:00",
"Level": "Error",
"MessageTemplate": "Failed executing DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}",
"Properties": {
"elapsed": "30,015",
"parameters": "@__id_0='?' (DbType = Int64)",
"commandType": "Text",
"commandTimeout": 30,
"newLine": "\n",
"commandText": "UPDATE servers AS s\nSET hits_received = s.hits_received + 1\nWHERE s.id = @__id_0",
"EventId": {
"Id": 20102,
"Name": "Microsoft.EntityFrameworkCore.Database.Command.CommandError"
},
"SourceContext": "Microsoft.EntityFrameworkCore.Database.Command",
"ActionId": "63acc236-57b2-4e9e-919c-839e796d6c7f",
"ActionName": "xxxx.Web.Controllers.External.ReportController.Report (AbuseBeacon.Web)",
"RequestId": "0HMURTMAQ7GN8:00000001",
"RequestPath": "/v1/xxxx",
"ConnectionId": "0HMURTMAQ7GN8"
}
}
{
"Timestamp": "2023-11-02T22:08:57.6615548+00:00",
"Level": "Error",
"MessageTemplate": "Failed executing DbCommand ({elapsed}ms) [Parameters=[{parameters}], CommandType='{commandType}', CommandTimeout='{commandTimeout}']{newLine}{commandText}",
"Properties": {
"elapsed": "30,015",
"parameters": "@__id_0='?' (DbType = Int64)",
"commandType": "Text",
"commandTimeout": 30,
"newLine": "\n",
"commandText": "UPDATE servers AS s\nSET hits_received = s.hits_received + 1\nWHERE s.id = @__id_0",
"EventId": {
"Id": 20102,
"Name": "Microsoft.EntityFrameworkCore.Database.Command.CommandError"
},
"SourceContext": "Microsoft.EntityFrameworkCore.Database.Command",
"ActionId": "63acc236-57b2-4e9e-919c-839e796d6c7f",
"ActionName": "xxxx.Web.Controllers.External.ReportController.Report (AbuseBeacon.Web)",
"RequestId": "0HMURTMAQ7GN8:00000001",
"RequestPath": "/v1/xxxx",
"ConnectionId": "0HMURTMAQ7GN8"
}
}
im using postgresql
18 replies