Maximum number of retries (6) exceeded - Unable to read data from the transport connection: Connection reset by peer.
See original GitHub issueSteps to reproduce
Deploy a .net core 3.1 app which is using Aurora PostgreSQL 10.14 to AWS lambda
Example of the configuration: var pgSqlConnString = Configuration[AppConstants.SettingKeyRdsConnString]; services.AddDbContext<TestRepositoryContext>(options => options.UseNpgsql(pgSqlConnString, x => x.EnableRetryOnFailure()), ServiceLifetime.Transient);
Connection string: “ConnectionString”: “Host=xxxx.us-east-1.rds.amazonaws.com;Database=xxxx_repository;Username=xxx;Password=xxx;Persist Security Info=True;SSL Mode=Require;Trust Server Certificate=true”
The issue
Getting lot of exceptions with this message "Maximum number of retries (6) exceeded while executing database operations with ‘NpgsqlRetryingExecutionStrategy’. " .
Unable to read data from the transport connection: Connection reset by peer. Please refer the stack trace
Stack trace:
Maximum number of retries (6) exceeded while executing database operations with 'NpgsqlRetryingExecutionStrategy'. See inner exception for the most recent failure.
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at TestAPI.Data.Impl.UserDao.GetUserAsync(String userId)
Exception while reading from stream
at Npgsql.NpgsqlReadBuffer.g__EnsureLong|40_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at Npgsql.NpgsqlConnector.g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at Npgsql.NpgsqlConnector.g__ReadMessageLong|194_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
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.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.ExecuteImplementationAsync[TState,TResult](Func`4 operation, Func`4 verifySucceeded, TState state, CancellationToken cancellationToken)
Unable to read data from the transport connection: Connection reset by peer.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Security.SslStream.g__InternalFillBufferAsync|215_0[TReadAdapter](TReadAdapter adap, ValueTask`1 task, Int32 min, Int32 initial)
at System.Net.Security.SslStream.ReadAsyncInternal[TReadAdapter](TReadAdapter adapter, Memory`1 buffer)
at Npgsql.NpgsqlReadBuffer.g__EnsureLong|40_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
Connection reset by peer
Npgsql version: Npgsql 5.0.4 and Npgsql.EntityFrameworkCore.PostgreSQL 3.1.11 PostgreSQL version: AWS Aurora PostgreSQL 10.14
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
We encountered the exactly same problem. Turns out this is an AWS Lambda specific problem. You can check out my analysis and possible solutions here: https://github.com/npgsql/npgsql/issues/3559#issuecomment-918171538
Duplicate of #3559