Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZw1H-0003If-QK for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Oct 2021 14:11:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mZw1F-0004MT-VL for pgsql-hackers@arkaria.postgresql.org; Mon, 11 Oct 2021 14:11:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mZw1F-0004ML-LC for pgsql-hackers@lists.postgresql.org; Mon, 11 Oct 2021 14:11:09 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mZw19-0002wg-IK for pgsql-hackers@postgresql.org; Mon, 11 Oct 2021 14:11:09 +0000 Received: by mail-lf1-x130.google.com with SMTP id r19so71888869lfe.10 for ; Mon, 11 Oct 2021 07:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=EDqEkL3TG+7LHN2p1ePNS0Hl5z1BQ+kfdSKIqqsOYMg=; b=fN4mAMSx1nWzacxHaUqvGmzLfF5QU4WIcbg6q2vKM9cMFYwjYSeTXZp+23d171p8VC WoZl+E2tQWYl+dY17CeYKZkrhtzID1G+Z8LeDOZGY7Ni8qwpLyfW/NzIlH18TPbwjdbG wOWcrz5TKizfysSeL9WKZG+w6ZV61o57UJkvYWoWsE/nBZkbnYTmaIdhhBhcO84GZWvD MaHYkJ9YU3XQMRefO20a9KVvyk0uDr1I0egI4xUh97ru4FlNngE+zsD2pArWe7YQ1glc I1YVCKXlcXmXwOnmquflGDHGE/4VHeQ7e1cRh2bzc+Dbyn/tgHpNA13ojUAU92bsxBqE uT2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=EDqEkL3TG+7LHN2p1ePNS0Hl5z1BQ+kfdSKIqqsOYMg=; b=G7U6W8QAd8hEzUJFTrs4BTPIVSn2oNXgGCgSvSS+uB9jLdT84Ca7HQK3vWwmU35Xba n3V085vwOlTEhzjHBWtEyKfHurrlG85PRkzI0TA6kBnF9RBbgOpiG1MAI+KPRTdK1EHO PfCt1C5WiX6YH0xiErEwqZzdMqlQW8DQ9hMfl34NYL4x891I8vo0z+gBhJ3gvTQM60uI sTxlXidsPM2+OGmL5t86jsCsFwEUhAFhTnEVd0NPDNcL4VW41nNzTAlyHyuVBF/Rm3FA +zWDPHdPeSX1GTXTq01vE0pYwqK0EO5msl2DORe9c1cIUrIuvizyYzqRdK2tGw2UeDjy bV9g== X-Gm-Message-State: AOAM533kUOHFLixc20siP86/H/qzgLTRzPPDEt5jHfuNf/IxKxhhwOJJ TmosD3TPMYb3s5LaT2dc8Gk= X-Google-Smtp-Source: ABdhPJzlUo8jaiiiHDGScb28GScyaaPTLk9Q4mhykxF3zzaoTzY8KWhme0RivjOJ5k7Ei8qIDm10ig== X-Received: by 2002:a05:6512:1581:: with SMTP id bp1mr29147114lfb.552.1633961435088; Mon, 11 Oct 2021 07:10:35 -0700 (PDT) Received: from [192.168.0.14] (5cfcadad.dynamic.mv.ru. [92.252.173.173]) by smtp.gmail.com with ESMTPSA id q7sm743734lfc.159.2021.10.11.07.10.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Oct 2021 07:10:34 -0700 (PDT) Subject: Re: Add client connection check during the execution of the query To: Thomas Munro , "tsunakawa.takay@fujitsu.com" Cc: pgsql-hackers , Tatsuo Ishii , Tom Lane , Andres Freund , Zhihong Yu References: <20190718.121906.432767475415875714.t-ishii@sraoss.co.jp> <79f5f12b-184f-dcdb-b22f-4f95b6a89f2d@postgrespro.ru> <6bd6945e-f02e-8ee8-b8c4-e8d74e283efd@gmail.com> From: Maksim Milyutin Message-ID: Date: Mon, 11 Oct 2021 17:10:29 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12.06.2021 07:24, Thomas Munro wrote: > On Fri, Apr 30, 2021 at 2:23 PM Thomas Munro 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