Re: Add client connection check during the execution of the query

Thomas Munro <thomas.munro@gmail.com>

From: Thomas Munro <thomas.munro@gmail.com>
To: Maksim Milyutin <milyutinma@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>, Tatsuo Ishii <ishii@sraoss.co.jp>, Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, Zhihong Yu <zyu@yugabyte.com>
Date: 2021-04-01T05:59:03Z
Lists: pgsql-hackers

Attachments

On Tue, Mar 30, 2021 at 10:00 AM Thomas Munro <thomas.munro@gmail.com> wrote:
> If we want to ship this in v14 we have to make a decision ASAP:
>
> 1.  Ship the POLLHUP patch (like v9) that only works reliably on
> Linux.  Maybe disable the feature completely on other OSes?
> 2.  Ship the patch that tries to read (like v7).  It should work on
> all systems, but it can be fooled by pipelined commands (though it can
> detect a pipelined 'X').
>
> Personally, I lean towards #2.

I changed my mind.  Let's commit the pleasingly simple Linux-only
feature for now, and extend to it to send some kind of no-op message
in a later release.  So this is the version I'd like to go with.
Objections?

I moved the GUC into tcop/postgres.c and tcop/tcopprot.h, because it
directly controls postgres.c's behaviour, not pqcomm.c's.  The latter
only contains the code to perform the check.

Commits

  1. Add WL_SOCKET_CLOSED for socket shutdown events.

  2. Use WL_SOCKET_CLOSED for client_connection_check_interval.

  3. Detect POLLHUP/POLLRDHUP while running queries.

  4. Improve timeout.c's handling of repeated timeout set/cancel.