Repository navigation
Closed
Description
Steps to reproduce
not deterministic.
The issue
On reading and writing data, following exception is thrown:
Npgsql.NpgsqlException (0x80004005): Received backend message ReadyForQuery while expecting ParseCompleteMessage. Please file a bug.
Exception Message:
Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details.
---> Npgsql.NpgsqlException (0x80004005): Received backend message ReadyForQuery while expecting ParseCompleteMessage. Please file a bug.
Stacktrace:
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches, IRelationalConnection connection, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _, Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
Npgsql version: Npgsql.EntityFrameworkCore.PostgreSQL v 5.0.5.1
Postgres: AWS Aurora 9.6.16
Operating system: (Debian 10) k8s -> docker-image -> mcr.microsoft.com/dotnet/aspnet:5.0 -> buster-slim-amd64
Metadata
Metadata
Assignees
Labels
No labels
Activity
roji commentedon Apr 27, 2021
@MirreJensen there's not much we can do with an error message... I understand that it's not deterministic, but it's usually possible do write a loop that runs until the error is triggered (sometimes executed across multiple threads). This is something you think you can do?
MirreJensen commentedon Apr 27, 2021
@roji we'll try to reproduce the error. Currently we are busy with rolling back to version 5.0.2.
roji commentedon Apr 27, 2021
@MirreJensen are you saying that 5.0.2 works perfectly without ever triggering this bug, while 5.0.5.1 consistently does trigger it (even if non-deterministically)?
efmk commentedon May 21, 2021
We've faced with similar issue.
After analysis we found that the reason is in concurrent keepalive. I believe it will be fixed in #Npgsql 3701
vonzshik commentedon May 21, 2021
@efmk is there a specific reason why you think it's the keepalive? On what version of npgsql did you test?
npgsql/npgsql#3701 is about making sure a user is not accidentally using the same connection from multiple threads.
efmk commentedon May 21, 2021
We were able to reproduce the issue (the same error message) by test running until failure. With specified keepalive (=1) in connection string, the test fails after 10 minutes. Without keepalive, the test does not fail after 3 hours of running. We use npgsql of version 5.0.5.
Also, in npgsql/npgsql#3701 said that keepalive is not 100% concurrent free.
vonzshik commentedon May 21, 2021
We're talking about just sending queries in a loop, nothing too fancy? I'll try to take a look today, but it will be great if you're able to provide a small repro.
That's true, but I would rather treat it as another keepalive bug, which we can fix independently of npgsql/npgsql#3701.
efmk commentedon May 21, 2021
In fact, the test we used is emulated a real application scenario, not just sending queries in a loop.
I tried to write a small repro test but can't implement the same behavior and reproduce the issue. I suppose there are specific conditions in the real app that can't be easily met.
But I can show application log with TRACE level for the broken connection. 3D26 it is BackendProcessId in HEX format.
Logger App.DataAccess.Storage.PostgreSql.NpgsqlConnectionProvider - is the application's logger. New NpgsqlConnection is created here.
I hope these logs could be useful for you. As I see in logs, connection has been closed during keepalive performing, maybe this somehow relates to the issue.
vonzshik commentedon May 21, 2021
@efmk it actually did help. I took a look not so long ago and found a potential bug with keepalive (npgsql/npgsql#3765). And your logs do confirm that it's possible that's the reason for your specific issue (as there is a race condition between connection closing and keepalive performing).
vonzshik commentedon Jul 26, 2021
Closing, since the issue should have been fixed with npgsql 5.0.7.
roji commentedon Jul 26, 2021
Duplicate of npgsql/npgsql#3765