efcore: Instead of just throwing, this common error hangs and causes a memory / CPU spike.
File a bug
In Production, a very normal String or binary data would be truncated error brought down our entire server, which is an Azure Service S2 with only 1.5g memory. To my surprise, I reproduced this on my local machine, and it seems that instead of just throwing an exception, it hangs. I was able to observe the iisprocess consuming a few gigs of memory before the exception finally throws.
In Production, it eventually timed out. The resources were not released and the server remained close to 100% utilization.
I tried updating to the latest EF, although I was already on 5.0.1 - no luck.
Any idea why this is happening and how I could avoid it?
Include your code
// other fields removed for clarity
var user = new User()
{
PhoneOffice = "intentionally long field; this field is varchar(12)"
};
Db.User.Add(user);
Db.SaveChanges();
Include stack traces
Include the full exception message and stack trace for any exception you encounter.
Use triple-tick fences for stack traces. For example:
String or binary data would be truncated. The statement has been terminated.
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(DbContext _, Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
at Keystone.Web.Controllers.AdminUser.Models.UserCreator.CreateKeystoneUser(String auth0UserId) in D:\Dev\Kinetiq\Keystone\Dev\Keystone.Web\Controllers\AdminUser\Models\UserCreator.cs:line 120
at Keystone.Web.Controllers.AdminUser.Models.UserCreator.CreateNew(UserVM model) in D:\Dev\Kinetiq\Keystone\Dev\Keystone.Web\Controllers\AdminUser\Models\UserCreator.cs:line 51
at Keystone.Web.Controllers.AdminUser.AdminUserController.Create(UserVM model) in D:\Dev\Kinetiq\Keystone\Dev\Keystone.Web\Controllers\AdminUser\AdminUserController.cs:line 95
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()
Include provider and version information
EF Core version: 5.0.1 and 5.0.2 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: net5.0 Operating system: Windows 10, and Azure Service IDE: Visual Studio 2019 16.8.4
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 20 (10 by maintainers)
You need to install the serilog EF Core package.
@kinetiq my code has my own connection string - yes, you’d need to adapt it to run against your environment (it’s very unlikely the original issue we’re discussing has anything to do with the connection string). The point is to try to put together a minimal repro which reproduces the error, to help you pinpoint where the problem is coming from.
Regarding what may be wrong with your app - I can’t really help with that since I have no idea what it’s doing 😃 Maybe in the case of this exception, there’s a code path where things go awry and do an endless loop or something… I’d recommend trying to narrow thing down, gradually excluding unrelated pieces of code until you either find the cause, or you have a minimal repro which you can submit to us for further investigation.
Alright, I am in the long process of gradually ripping things out of this project… Stay tuned.