pgsql: Make PQcancel use the PGconn's tcp_user_timeout and keepalives s

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make PQcancel use the PGconn's tcp_user_timeout and keepalives s
Date: 2022-01-18 19:13:28
Message-ID: E1n9tv6-0005GV-Hc@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make PQcancel use the PGconn's tcp_user_timeout and keepalives settings.

If connectivity to the server has been lost or become flaky, the
user might well try to send a query cancel. It's highly annoying
if PQcancel hangs up in such a case, but that's exactly what's likely
to happen. To ameliorate this problem, apply the PGconn's
tcp_user_timeout and keepalives settings to the TCP connection used
to send the cancel. This should be safe on Unix machines, since POSIX
specifies that setsockopt() is async-signal-safe. We are guessing
that WSAIoctl(SIO_KEEPALIVE_VALS) is similarly safe on Windows.
(Note that at least in psql and our other frontend programs, there's
no safety issue involved anyway, since we run PQcancel in its own
thread rather than in a signal handler.)

Most of the value here comes from the expectation that tcp_user_timeout
will be applied as a connection timeout. That appears to happen on
Linux, even though its tcp(7) man page claims differently. The
keepalive options probably won't help much, but as long as we can
apply them for not much code, we might as well.

Jelte Fennema, reviewed by Fujii Masao and myself

Discussion: https://postgr.es/m/AM5PR83MB017870DE81FC84D5E21E9D1EF7AA9@AM5PR83MB0178.EURPRD83.prod.outlook.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5987feb70b5bbb1fc4e64d433f490df08d91dd45

Modified Files
--------------
doc/src/sgml/libpq.sgml | 4 +-
src/interfaces/libpq/fe-connect.c | 249 +++++++++++++++++++++++++++++---------
src/interfaces/libpq/libpq-int.h | 7 ++
3 files changed, 204 insertions(+), 56 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2022-01-18 20:15:44 Re: pgsql: Test replay of regression tests, attempt II.
Previous Message Thomas Munro 2022-01-18 18:56:38 Re: pgsql: Test replay of regression tests, attempt II.