Skip to content

Connection time outs without any warning. An output about the reason is expected. #874

Closed

Description

@sirentek

I use EntityFramework7.Npgsql 3.1.0-rc1-1 and ef rc1-final versions.

I can connect to the host using DbVisualizer with these params:
server=192.168.1.72
port=5432
database=samdb
userid=john
password=mysecret

optionsBuilder.UseNpgsql($"Server=192.168.1.72;Port=5432;Database=samdb;UserId=john;Password=mysecret");

I run => dnx ef migrations add InitialMigration
done.
I run => dnx ef database update
System.TimeoutException: The operation has timed out.
at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.Open()
at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection)
at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection connection)
at Npgsql.NpgsqlConnection.OpenInternal(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnection.Open()
at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
at Microsoft.Data.Entity.Storage.Internal.NpgsqlDatabaseCreator.Exists()
at Microsoft.Data.Entity.Migrations.HistoryRepository.Exists()
at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.Data.Entity.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)

When I change the username or password or server or port or databasename, it creates the same System.TimeoutException.
Changing any parameter value doesn't have any effect in the result.

I think outputs such as "invalid user creditentals", "server doesn't exist" would be better.

Activity

  1. self-assigned this
    on Nov 19, 2015
  2. sirentek commented on Nov 21, 2015

    @sirentek
    Author

    The database exists in a linux host.

    When the client is Windows:
    Works as expected.

    When the client is Linux:
    It doesn't connect. (Timeout exception)
    It doesn't connect to localhost either. (Timeout exception)

  3. roji commented on Nov 21, 2015

    @roji
    Member
  4. sirentek commented on Nov 22, 2015

    @sirentek
    Author

    It is the part of the NpgsqlConnector class, Connect() method.

                    var write = new List<Socket> { socket };
                    var error = new List<Socket> { socket };
                    Socket.Select(null, write, error, perIpTimeout);
                    var errorCode = (int) socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Error);
                    if (errorCode != 0) {
                        throw new SocketException((int)socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Error));
                    }
                    if (!write.Any())
                    {
                        Log.Warn(
                            $"Timeout after {new TimeSpan(perIpTimeout*10).TotalSeconds} seconds when connecting to {ips[i]}");
                        try { socket.Dispose(); }
                        catch
                        {
                            // ignored
                        }
                        if (i == ips.Length - 1)
                        {
                            throw new TimeoutException();
                        }
                        continue;
                    }
    

    After the following line is called:
    =>Socket.Select(null, write, error, perIpTimeout);

    In Linux:
    The list write doesn't have any elements after the following line is called:
    As a result it enters the if (!write.Any()) block and creates "Timeout exception" there.

    In Windows:
    The list write has the element. It works.

    So the problem seems to be at:
    =>Socket.Select(null, write, error, perIpTimeout);

    I don't have any idea why it behaves differently in Linux..

  5. sirentek commented on Nov 22, 2015

    @sirentek
    Author

    I think it may not be a Npgsql related issue. I have created an issue about Socket.Select() method here: https://github.com/dotnet/corefx/issues/4631

  6. damageboy commented on Nov 23, 2015

    @damageboy
    Contributor

    @sirentek It's not clear to me, what runtime exactly are you experiencing this on? Mono / CoreCLR?

  7. damageboy commented on Nov 23, 2015

    @damageboy
    Contributor

    @roji this doesn't look to be ef7 related to me, pure CoreCLR, IMO

  8. sirentek commented on Nov 23, 2015

    @sirentek
    Author

    @damageboy I use CoreCLR. It was 1.0.0-rc2-16177.
    Socket creates the exception. But this exception is catched and not thrown here in NpsqlConnector.cs:

            if (e.SocketErrorCode != SocketError.WouldBlock)
                    {
                        throw;
                    }
    

    So developer will never know when there is a socket exception at the time Socket.DoConnect() method is called. Actually the exception takes place at there and this makes Socket.Select() method behave different. I think problem is System.Net.Sockets package just as you mentioned pure CoreCLR issue.

    Should I close this issue ? ( I have already opened about this at https://github.com/dotnet/corefx/issues/4631 )

  9. pgavlin commented on Nov 23, 2015

    @pgavlin

    This is a Linux-specific CoreFX issue. A fix is in progress.

  10. damageboy commented on Nov 23, 2015

    @damageboy
    Contributor

    Yeap, looks like this should be closed, I'll let you do the deed

  11. sirentek commented on Nov 23, 2015

    @sirentek
    Author

    @damageboy Thanks!

  12. sirentek commented on Dec 1, 2015

    @sirentek
    Author

    https://github.com/dotnet/corefx/issues/4631 => fixes select method but the problem still resists.

    I have tested the new libraries (system.net.sockets version rc2-530) using coreclr runtime and got the same error (connection time out).

    This bug blocks us using ngpsql with coreclr runtime. So I created an other issue here:
    Please see https://github.com/dotnet/corefx/issues/4733

    For those who want to use ngpsql in linux : dnx mono runtime version beta8 works.
    For dnx mono-rc runtime versions, updating mono installation to 4.3 is required.

  13. thmulvany commented on Jan 8, 2016

    @thmulvany

    Anyone still having any issues (e.g. System.Net.Security, System.Net.NetworkInformation or PG timeout) in a .NET Core (not Mono) app using EF7 + NpgSql EF7 provider please see https://github.com/dotnet/corefx/issues/4631#issuecomment-165893079 and https://github.com/dotnet/corefx/issues/4631#issuecomment-169551945

  14. tynar commented on Apr 24, 2016

    @tynar

    Same as Nickolas Acosta,

    dnvm 1.0.0-rc2-15546,
    dnx
    Microsoft .NET Execution environment
    Version: 1.0.0-rc1-16609
    Type: CoreClr
    Architecture: x64
    OS Name: Linux
    OS Version: ubuntu 14.04
    Runtime Id: ubuntu.14.04-x64

    postgre: 9.5

  15. PcMaKeR commented on May 2, 2016

    @PcMaKeR

    Same problem:

    System.TimeoutException: The operation has timed out.
       at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnector.Open()
       at Npgsql.NpgsqlConnectorPool.GetPooledConnector(NpgsqlConnection Connection)
       at Npgsql.NpgsqlConnectorPool.RequestConnector(NpgsqlConnection connection)
       at Npgsql.NpgsqlConnection.OpenInternal(NpgsqlTimeout timeout)
       at Npgsql.NpgsqlConnection.Open()
       at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
       at Microsoft.Data.Entity.Storage.Internal.NpgsqlDatabaseCreator.Exists()
       at Microsoft.Data.Entity.Migrations.HistoryRepository.Exists()
       at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMigration)
       at Microsoft.Data.Entity.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
       at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
    

    dnx --version
    Microsoft .NET Execution environment
    Version: 1.0.0-rc1-16609
    Type: CoreClr
    Architecture: x64
    OS Name: Linux
    OS Version: ubuntu 14.04
    Runtime Id: ubuntu.14.04-x64

    EntityFramework and Npgsql versions:

    "EntityFramework.Relational": "7.0.0-rc1-final", "EntityFramework7.Npgsql": "3.1.0-rc1-3", "EntityFramework7.Npgsql.Design": "3.1.0-rc1-5", "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.Core": "7.0.0-rc1-final", "EntityFramework.Relational.Design": "7.0.0-rc1-final", "Microsoft.Extensions.CodeGeneration.EntityFramework": "1.0.0-rc1-final",

  16. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions