efcore.pg: 5.0.0: Npgsql.NpgsqlException (0x80004005): Exception while reading from stream

Hello, after upgrading to 5.0.0 version, this is the error i get for long queries. Long queries get timeout. Happens only on 5.0.0. The same queries / codebase works fine with V3.1.2 or when connected with any local sql client to the same database.

The following is the exception

System.InvalidOperationException
An exception has been raised that is likely due to a transient failure.

System.InvalidOperationException: An exception has been raised that is likely due to a transient failure.
 ---> Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
 ---> System.TimeoutException: Timeout during reading attempt
   at Npgsql.NpgsqlConnector.<ReadMessage>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.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(DbContext _, Boolean result, CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.MoveNextAsync()
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleAsync[TSource](IAsyncEnumerable`1 asyncEnumerable, CancellationToken cancellationToken)

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (10 by maintainers)

Most upvoted comments

@roji Setting a Command Timeout=0 still does not fix the issue. I will try to compile a runnable sample hopefully. if there is something else you would like me to try, that would be helpful.

@etiennecl’s problem was moved to the new issue, but it’s hard to say what was here. Let’s wait a week for @asadcr and close the issue in case of no response. Otherwise, we can close it right now and reopen later.

@roji did 3.1.2 support an async timeout?

In this case, good news: I’ve been able to repeat this error.

public class BugClass
{
	public string? SomeString { get; set; }
}

[Test]
public void Bug1599()
{
	var expected = new BugClass { SomeString = new string('5', 8174) };
	using (var conn = OpenConnection())
	using (var cmd = new NpgsqlCommand(@"SELECT @p1, @p2", conn))
	{
		conn.TypeMapper.UseJsonNet(new[] { typeof(BugClass) });

		cmd.Parameters.AddWithValue("p1", expected);
		cmd.Parameters.AddWithValue("p2", expected);
		using (var reader = cmd.ExecuteReader()) { }
	}
}

Right now, @YohDeadfall is taking a look.

The new version from myget didn’t resolve the issue.