New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sirentek opened this Issue Nov 19, 2015 · 16 comments

Comments

Projects
None yet
7 participants
@sirentek
Copy link

sirentek commented Nov 19, 2015

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.

@roji roji added bug ef7 labels Nov 19, 2015

@roji roji self-assigned this Nov 19, 2015

@sirentek

This comment has been minimized.

Copy link

sirentek commented Nov 21, 2015

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)

@roji

This comment has been minimized.

Copy link
Member

roji commented Nov 21, 2015

@sirentek

This comment has been minimized.

Copy link

sirentek commented Nov 22, 2015

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..

@sirentek

This comment has been minimized.

Copy link

sirentek commented Nov 22, 2015

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

@damageboy

This comment has been minimized.

Copy link
Contributor

damageboy commented Nov 23, 2015

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

@damageboy

This comment has been minimized.

Copy link
Contributor

damageboy commented Nov 23, 2015

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

@sirentek

This comment has been minimized.

Copy link

sirentek commented Nov 23, 2015

@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 dotnet/corefx#4631 )

@pgavlin

This comment has been minimized.

Copy link

pgavlin commented Nov 23, 2015

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

@damageboy

This comment has been minimized.

Copy link
Contributor

damageboy commented Nov 23, 2015

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

@sirentek

This comment has been minimized.

Copy link

sirentek commented Nov 23, 2015

@damageboy Thanks!

@sirentek sirentek closed this Nov 23, 2015

@roji

This comment has been minimized.

Copy link
Member

roji commented Dec 1, 2015

FYI dotnet/corefx#4631 just got closed

@sirentek

This comment has been minimized.

Copy link

sirentek commented Dec 1, 2015

dotnet/corefx#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 dotnet/corefx#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.

@thmulvany

This comment has been minimized.

Copy link

thmulvany commented Jan 8, 2016

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 dotnet/corefx#4631 (comment) and dotnet/corefx#4631 (comment)

@ghost

This comment has been minimized.

Copy link

ghost commented Mar 28, 2016

got this when trying a dnx ef database update.

ubuntu server, 1.0.0-rc1-update1 coreclr

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)
@tynar

This comment has been minimized.

Copy link

tynar commented Apr 24, 2016

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

@PcMaKeR

This comment has been minimized.

Copy link

PcMaKeR commented May 2, 2016

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",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment