I am writing a .NET app that uses Entity Framework to write data to a Postgres v12 database. The app itself watches the filesystem and writes data to the database every time it sees changes.
The data itself is both inserts and updates, spread across multiple tables.
This works so far - most of the time.
However, quite regularly the program simply hangs, it stops responding. It looks like the more data to write, the more often the problem occurs.
After restarting the app, sometimes it works and sometimes it doesn't.
The actual hanging happens when calling
DbContext.SaveChanges
Then in the Postgres log I find an entry:
LOG: could not receive data from client: unrecognized winsock error 10054
LOG: incomplete message from client (Translated from German)
LOG: could not receive data from client: unrecognized winsock error 10054
LOG: incomplete message from client
Google didn't help me with the message, there it's always about connection problems, if you program sockets yourself.
Does anyone have an idea how I can proceed here? Can I change something in the connection parameters to Postgres or where to start looking at?
The Postgres database itself runs on the same system as my app, the stacktrace when it hangs:
[Übergang von Verwaltet zu Nativ] Annotated Frame
System.Net.Sockets.dll!System.Net.Sockets.SocketPal.Receive(System.Net.Sockets.SafeSocketHandle handle, System.Span<byte> buffer, System.Net.Sockets.SocketFlags socketFlags, out int bytesTransferred) Unknown Non-user code. Skipped loading symbols.
System.Net.Sockets.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) Unknown Non-user code. Skipped loading symbols.
System.Net.Sockets.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int offset, int size) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlReadBuffer.Ensure.__EnsureLong|40_0(Npgsql.NpgsqlReadBuffer buffer, int count, bool async, bool readingNotifications) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlConnector.ReadMessage.__ReadMessageLong|194_0(Npgsql.NpgsqlConnector connector, bool async, Npgsql.DataRowLoadingMode dataRowLoadingMode, bool readingNotifications, bool isReadingPrependedMessage) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlConnector.ReadMessage(bool async, Npgsql.DataRowLoadingMode dataRowLoadingMode, bool readingNotifications) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlDataReader.NextResult(bool async, bool isConsuming, System.Threading.CancellationToken cancellationToken) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlDataReader.NextResult() Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior behavior, bool async, System.Threading.CancellationToken cancellationToken) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteReader(System.Data.CommandBehavior behavior) Unknown Non-user code. Skipped loading symbols.
Npgsql.dll!Npgsql.NpgsqlCommand.ExecuteDbDataReader(System.Data.CommandBehavior behavior) Unknown Non-user code. Skipped loading symbols.
System.Data.Common.dll!System.Data.Common.DbCommand.ExecuteReader() Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(Microsoft.EntityFrameworkCore.Storage.RelationalCommandParameterObject parameterObject) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(System.Collections.Generic.IEnumerable<Microsoft.EntityFrameworkCore.Update.ModificationCommandBatch> commandBatches, Microsoft.EntityFrameworkCore.Storage.IRelationalConnection connection) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.Relational.dll!Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(System.Collections.Generic.IList<Microsoft.EntityFrameworkCore.Update.IUpdateEntry> entries) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(System.Collections.Generic.IList<Microsoft.EntityFrameworkCore.Update.IUpdateEntry> entriesToSave) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Microsoft.EntityFrameworkCore.DbContext _, bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Npgsql.EntityFrameworkCore.PostgreSQL.dll!Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute<bool, int>(bool state, System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, int> operation, System.Func<Microsoft.EntityFrameworkCore.DbContext, bool, Microsoft.EntityFrameworkCore.Storage.ExecutionResult<int>> verifySucceeded) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.SaveChanges(bool acceptAllChangesOnSuccess) Unknown Non-user code. Skipped loading symbols.
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.SaveChanges() Unknown Non-user code. Skipped loading symbols.
> SPCDataWriterWorker.dll!Promess.MeasurementResults.SPCDataWriterWorker.Globals.SaveDBChangesWithEvent(Promess.MeasurementResults.Model.ResultContext db, string sTablename) Line 56 C# Symbols loaded.
Referenced packages:
SaveDBChangesWithEvent
is just that:
internal static void SaveDBChangesWithEvent(ResultContext db, string sTablename)
{
if (!db.ChangeTracker.AutoDetectChangesEnabled)
{
db.ChangeTracker.DetectChanges();
}
int iSavedRowCount = db.SaveChanges();
Debug.Trace($"{iSavedRowCount} geänderte Datensätze in {sTablename}");
Globals.FireProcessFileStep(string.Format(
Texts.ProcessStepWriteDBChangeCount, iSavedRowCount, sTablename), Globals.EventsSeverity.Debug);
}
It really looks like the error is gone after updating the referenced packages. I will examine it further and post a more complete example once it happens again. Thanks to all of you