Re: connection timeout hint

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: connection timeout hint
Date: 2023-12-04 03:10:11
Message-ID: 652683.1701659411@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:
> When one tries to connect to a server and port which is protected by a
> firewall, ones get messages like this:

> Unix:
> psql: error: connection to server at "192.168.0.26", port 5432 failed:
> Connection timed out
> Is the server running on that host and accepting TCP/IP connections?

> Windows:
> psql: error: connection to server at "192.168.0.26", port 5432 failed:
> Connection timed out (0x0000274C/10060)
> Is the server running on that host and accepting TCP/IP connections?

> But the hint given is unhelpful, and even positively misleading.

Well, maybe. I think you're right that it would be useful to give
different hints for ETIMEDOUT and ECONNREFUSED, but sadly it seems
not uncommon for systems to just drop connection requests that
there's no listening process for.

Can we break down the possible cases any further?

* Target host doesn't exist or is down: could give ETIMEDOUT,
EHOSTDOWN, or EHOSTUNREACH.

* Host is up, but PG server is not running or not listening on that
socket: ideally ECONNREFUSED, but could be ETIMEDOUT if the local
firewall blocks it.

* Server is running, but firewall blocks reaching it: almost
certainly ETIMEDOUT.

Are there more cases?

The current hint is already reasonably on-point for EHOSTDOWN,
EHOSTUNREACH, ECONNREFUSED. I agree it's too specific for
ETIMEDOUT, but what exactly would be a better message in view
of the multitude of possible causes?

> Is there some portable way to detect this cause of the connection problem
> (connection timeout)

No, I don't think so. We have the kernel errno to work with
and little more.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2023-12-04 03:21:24 gai_strerror() is not thread-safe on Windows
Previous Message Peter Geoghegan 2023-12-04 03:02:55 Re: [RFC] Clang plugin for catching suspicious typedef casting