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: pgsql-hackers <pgsql-hackers@postgresql.org>
Cc: 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-03-24T03:08:13Z
Lists: pgsql-hackers
Attachments
- v8-0001-Detect-POLLHUP-while-running-queries.patch (text/x-patch) patch v8-0001
Going back a couple of years to something Konstantin said: On Sat, Aug 3, 2019 at 4:40 AM Konstantin Knizhnik <k.knizhnik@postgrespro.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).
Commits
-
Add WL_SOCKET_CLOSED for socket shutdown events.
- 50e570a59e7f 15.0 landed
-
Use WL_SOCKET_CLOSED for client_connection_check_interval.
- cba5b994c990 15.0 landed
-
Detect POLLHUP/POLLRDHUP while running queries.
- c30f54ad732c 14.0 landed
-
Improve timeout.c's handling of repeated timeout set/cancel.
- 09cf1d522676 14.0 cited