question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random "Connection refused" on Linux

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
jvenemacommented, Mar 2, 2020

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

0reactions
rojicommented, Mar 7, 2020

@jvenema can you please submit a runnable sample for that?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What can be the reasons of connection refused errors?
Connection refused means that the port you are trying to connect to is not actually open. So either you are connecting to the...
Read more >
Random "connection refused" using SCP commands in a ...
And now some of the individual SCP commands fail at random with "connections refused". But the next SCP command in the script works....
Read more >
How to solve 'Connection refused' errors in SSH connection?
I can confirm this exact issue: It's not a simple connectivity issue. The ethernet link does not change state; server is reachable via...
Read more >
SSH Connection Refused : r/linuxquestions
So a connection refused means it's listening. If the port was closed you would get a timeout. as root. sshd -T. verify port...
Read more >
SSH connection refused for External IP - General
When I SSH into my Rocky Linux server via internal IP (10.10.1.100), it works fine. Via the external IP, (from Googling 'what's my...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found