question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Maximum number of retries (6) exceeded - Unable to read data from the transport connection: Connection reset by peer.

See original GitHub issue

Steps 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cfbaocommented, Sep 23, 2021

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

0reactions
rojicommented, Sep 23, 2021

Duplicate of #3559

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Error Unable to read data from transport connection. ...
1 Answer. Unable to read data from the transport connection: Connection reset by peer. This error usually means that the target machine is ......
Read more >
System.IO.IOException: Unable to read data from the ...
Hi, I don't understand why some times I got the below exception? System.AggregateException: One or more errors occurred. (The SSL connection ...
Read more >
Azure EF Core and EF 6 SQL database connection resiliency
This error occurs when the SQL database is idle, and therefore the SQL connection fails before the database is active.
Read more >
Troubleshoot common connection issues to Azure SQL ...
These connection problems can be caused by reconfiguration, firewall settings, a connection timeout, incorrect login information, or failure to ...
Read more >
How does java net SocketException Connection reset happen
In your case it seems that the connection has been closed by the server end of the connection. This could be an issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found