Skip to content

Connection aborted exception during EnsureDeleted call #3671

@MaceWindu

Description

@MaceWindu

Npgsql.EntityFrameworkCore.PostgreSQL.NodaTime: 10.0.0 (10.0.0-rc.2 works)

Error looks same as #3326 but have different repro code.

Reduced code (real case use different contexts).
Important point:

  • UseNodaTime required
  • ReplaceService required
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

internal static class Program
{
    private static void Main()
    {
        var connectionString = "<CS_HERE>";

        using (var context = CreateContext(false)) { }
        using (var context = CreateContext(true)) { }
        using (var context = CreateContext(false)) { }

        DbContext CreateContext(bool replace)
        {
            var optionsBuilder = new DbContextOptionsBuilder<DbContext>()
                .UseNpgsql(connectionString, o => o.UseNodaTime());

            if (replace)
            {
                optionsBuilder = optionsBuilder
                    .ReplaceService<IValueConverterSelector, ValueConverterSelector>();
            }

            var ctx = new DbContext(optionsBuilder.Options);

            ctx.Database.EnsureDeleted();
            ctx.Database.EnsureCreated();

            return ctx;
        }
    }
}

On third context creation during EnsureDeleted call following error triggered:

System.InvalidOperationException
  HResult=0x80131509
  Message=An exception has been raised that is likely due to a transient failure.
  Source=Npgsql.EntityFrameworkCore.PostgreSQL
  StackTrace:
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation, Func`2 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, TState state, Func`2 operation)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TResult](IExecutionStrategy strategy, Func`1 operation)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists()
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureDeleted()
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureDeleted()
   at Program.<Main>g__CreateContext|0_0(Boolean replace, <>c__DisplayClass0_0& )

  This exception was originally thrown at this call stack:
    System.Net.Sockets.Socket.Receive(byte[], int, int, System.Net.Sockets.SocketFlags)
    System.Net.Sockets.NetworkStream.Read(byte[], int, int)

Inner Exception 1:
NpgsqlException: Exception while reading from stream

Inner Exception 2:
IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine..

Inner Exception 3:
SocketException: An established connection was aborted by the software in your host machine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions