Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnyao-0008RT-3Y for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jul 2019 05:04:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hnyal-0003yL-Dp for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jul 2019 05:04:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnyal-0003yD-59 for pgsql-hackers@lists.postgresql.org; Thu, 18 Jul 2019 05:04:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hnyac-0001yp-7k for pgsql-hackers@postgresql.org; Thu, 18 Jul 2019 05:04:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x6I54Dem031565; Thu, 18 Jul 2019 01:04:13 -0400 From: Tom Lane To: Tatsuo Ishii cc: thomas.munro@gmail.com, s.kelvich@postgrespro.ru, pgsql-hackers@postgresql.org Subject: Re: Add client connection check during the execution of the query In-reply-to: <20190718.134308.909519174866822804.t-ishii@sraoss.co.jp> References: <20190718.121906.432767475415875714.t-ishii@sraoss.co.jp> <20190718.134308.909519174866822804.t-ishii@sraoss.co.jp> Comments: In-reply-to Tatsuo Ishii message dated "Thu, 18 Jul 2019 13:43:08 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31563.1563426253.1@sss.pgh.pa.us> Date: Thu, 18 Jul 2019 01:04:13 -0400 Message-ID: <31564.1563426253@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tatsuo Ishii writes: >> Yeah, the timer logic is wrong. I didn't have time to look into it >> but with truss/strace for some reason I see 3 setitimer() syscalls for >> every query, but I think this doesn't even need to set the timer for >> every query. > Hum. I see 2 settimer(), instead of 3. src/backend/utils/misc/timeout.c is not really designed for there to be timeouts that persist across multiple queries. It can probably be made better, but this patch doesn't appear to have touched any of that logic. To point to just one obvious problem, the error recovery path (sigsetjmp block) in postgres.c does disable_all_timeouts(false); which cancels *all* timeouts. Probably don't want that behavior anymore. I think the issue you're complaining about may have to do with the fact that if there's no statement timeout active, both enable_statement_timeout and disable_statement_timeout will call "disable_timeout(STATEMENT_TIMEOUT, false);". That does nothing, as desired, if there are no other active timeouts ... but if there is one, ie the client_connection timeout, we'll end up calling schedule_alarm which will call setitimer even if the desired time-of-nearest-timeout hasn't changed. That was OK behavior for the set of timeouts that the code was designed to handle, but we're going to need to be smarter now. regards, tom lane