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

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Tatsuo Ishii <ishii(at)sraoss(dot)co(dot)jp>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andres Freund <andres(at)anarazel(dot)de>, Zhihong Yu <zyu(at)yugabyte(dot)com>
Subject: Re: Add client connection check during the execution of the query
Date: 2021-03-24 03:08:13
Message-ID: CA+hUKGL9LLNE8_+rBkRzBhmXA1XHEzJVqQr4T4fqzngqp66=-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Going back a couple of years to something Konstantin said:

On Sat, Aug 3, 2019 at 4:40 AM Konstantin Knizhnik
<k(dot)knizhnik(at)postgrespro(dot)ru> wrote:
> But I wonder why we can not perform just pool with POLLOUT flag and zero
> timeout.
> If OS detected closed connection, it should return POLLHUP, should not it?
> I am not sure if it is more portable or more efficient way - just seems
> to be a little bit more natural way (from my point of view) to check if
> connection is still alive.

... Andres just asked me the same question, when we were discussing
the pq_peekmessage() patch (v7). I had remembered that POLLHUP didn't
work for this type of thing, from some earlier attempt at something
similar, and indeed on my first attempt to do that here as an
alternative design, it did not work... with TCP sockets (localhost)...
though it did work with Unix sockets. Gah! Then he pointed me at
POLLRDHUP (a Linux only extension) and that did seem to work in all
cases I tried. But without that, this v8 patch doesn't seem to work
on FreeBSD (TCP), and for the rest of the menagerie, who knows?
Here's a sketch patch like that for discussion.

It's frustrating, because this patch is so simple, and doesn't have
v7's problem with pipelined queries. Hmm.

(I tried to make it work on Windows too by reading the manual, no idea
if that part compiles or works).

Attachment Content-Type Size
v8-0001-Detect-POLLHUP-while-running-queries.patch text/x-patch 12.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2021-03-24 03:09:59 Re: 64-bit XIDs in deleted nbtree pages
Previous Message Julien Rouhaud 2021-03-24 03:07:13 Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?