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

From: Maksim Milyutin <milyutinma(at)gmail(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, 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-10-11 14:10:29
Message-ID: f8547534-47ec-0f7c-fb6a-a7eb347f5a7e@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 12.06.2021 07:24, Thomas Munro wrote:

> On Fri, Apr 30, 2021 at 2:23 PM Thomas Munro <thomas(dot)munro(at)gmail(dot)com> wrote:
>> Here's something I wanted to park here to look into for the next
>> cycle: it turns out that kqueue's EV_EOF flag also has the right
>> semantics for this. That leads to the idea of exposing the event via
>> the WaitEventSet API, and would the bring
>> client_connection_check_interval feature to 6/10 of our OSes, up from
>> 2/10. Maybe Windows' FD_CLOSE event could get us up to 7/10, not
>> sure.
> Rebased. Added documentation tweak and a check to reject the GUC on
> unsupported OSes.

Good work. I have tested your patch on Linux and FreeBSD on three basic
cases: client killing, cable breakdown (via manipulations with firewall)
and silent closing client connection before completion of previously
started query in asynchronous manner. And all works fine.

Some comments from me:

 bool
 pq_check_connection(void)
 {
-#if defined(POLLRDHUP)
+    WaitEvent events[3];

3 is looks like as magic constant. We might to specify a constant for
all event groups in FeBeWaitSet.

+    ModifyWaitEvent(FeBeWaitSet, FeBeWaitSetLatchPos, WL_LATCH_SET, NULL);
+    ModifyWaitEvent(FeBeWaitSet, FeBeWaitSetSocketPos,
WL_SOCKET_CLOSED, NULL);
+    rc = WaitEventSetWait(FeBeWaitSet, 0, events, lengthof(events), 0);
+    ModifyWaitEvent(FeBeWaitSet, FeBeWaitSetLatchPos, WL_LATCH_SET,
MyLatch);

AFAICS, side effect to
(FeBeWaitSet->events[FeBeWaitSetSocketPos]).events by setting
WL_SOCKET_CLOSED value under calling of pq_check_connection() function
doesn't have negative impact later, does it? That is, all
WaitEventSetWait() calls have to setup socket events on its own from
scratch.

--
Regards,
Maksim Milyutin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mikael Kjellström 2021-10-11 14:15:13 Re: Time to upgrade buildfarm coverage for some EOL'd OSes?
Previous Message Yura Sokolov 2021-10-11 13:31:17 Re: Double partition lock in bufmgr