npgsql: Random "Connection refused" on Linux

Hello, we experience random SocketExceptions on all Linux VMs with pgBouncer:

System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)
   at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state, Boolean flowContext)
   at System.Net.Sockets.Socket.BeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1](Func`4 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, Object state, TaskCreationOptions creationOptions)
   at Npgsql.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.RawOpen(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at PgBouncePinger.Program.Main(String[] args)

We use host=localhost, and tracing shows that error is related to [::1], because issue is not encountered then using host=127.0.0.1 .

Trace:

USUAL TRACE: TRACE Opening connection… TRACE Opening connection… TRACE Attempting to connect to [::1]:6543 TRACE Failed to connect to [::1]:6543 TRACE Attempting to connect to 127.0.0.1:6543 TRACE Socket connected to localhost:6543 TRACE Authenticating…

RANDOM ERROR: TRACE Opening connection… TRACE Opening connection… TRACE Attempting to connect to [::1]:6543 ERROR Breaking connector TRACE Cleaning up connector TRACE Closing connector

TRUE CONNECTION REFUSED (port not open): TRACE Opening connection… TRACE Opening connection… TRACE Attempting to connect to [::1]:6543 TRACE Failed to connect to [::1]:6543 TRACE Attempting to connect to 127.0.0.1:6543 TRACE Failed to connect to 127.0.0.1:6543 ERROR Breaking connector TRACE Cleaning up connector TRACE Closing connector

Maybe, possible solution would be to move this line into try block below.

https://github.com/npgsql/npgsql/blob/91d23f90ef00eadc7c07966833959a5b3f877127/src/Npgsql/NpgsqlConnector.cs#L760

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 23 (11 by maintainers)

Most upvoted comments

100%. I can even use psql.

On Sunday, March 1, 2020, Shay Rojansky notifications@github.com wrote:

@jvenema https://github.com/jvenema are you 100% sure that you can telnet to the IP on port 5432, but Npgsql running on that same client throws “Connection refused” trying to connect to the same server IP and port? That would be very strange - as I wrote above https://github.com/npgsql/npgsql/issues/2198#issuecomment-527110584, this is a low-level networking error that has nothing to do with Npgsql; the latter only attempts to establish a regular TCP connection.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/npgsql/npgsql/issues/2198?email_source=notifications&email_token=AABM7FMRB6G45VRQDGDCHVDRFKDY3A5CNFSM4F6BY5K2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENNDTDY#issuecomment-593115535, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABM7FPE6CEFYMYU3Q2YL23RFKDY3ANCNFSM4F6BY5KQ .

– Jerod Venema