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 1nFf64-0003wI-Qu for pgsql-general@arkaria.postgresql.org; Thu, 03 Feb 2022 16:36:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFf63-0000dp-0r for pgsql-general@arkaria.postgresql.org; Thu, 03 Feb 2022 16:36:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFf62-0000dZ-Lu for pgsql-general@lists.postgresql.org; Thu, 03 Feb 2022 16:36:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nFf60-0007Cm-5q for pgsql-general@lists.postgresql.org; Thu, 03 Feb 2022 16:36:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 213GaRD1272368; Thu, 3 Feb 2022 11:36:27 -0500 From: Tom Lane To: Simon Riggs cc: Michael Harris , Alvaro Herrera , pgsql-general@lists.postgresql.org Subject: Re: Undetected Deadlock In-reply-to: References: <202201252311.4jc4gpdzwwu7@alvherre.pgsql> Comments: In-reply-to Simon Riggs message dated "Thu, 03 Feb 2022 09:04:39 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <272366.1643906187.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Feb 2022 11:36:27 -0500 Message-ID: <272367.1643906187@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Simon Riggs writes: > On Thu, 3 Feb 2022 at 06:25, Michael Harris wrote: >> Some of these functions trigger fetching of remote resources, for >> which a timeout is set using `alarm`. The function unfortunately does >> not re-establish any pre-existing interval timers after it is done, >> which leads to postgresql missing it's own expected alarm signal. >> = >> The reason that this was not affecting us on previous postgres >> versions was this commit: >> = >> https://github.com/postgres/postgres/commit/09cf1d52267644cdbdb73429401= 2cf1228745aaa#diff-b12a7ca3bf9c6a56745844c2670b0b28d2a4237741c395dda318c6c= c3664ad4a >> = >> After this commit, once an alarm is missed, that backend never sets >> one again, so no timeouts of any kind will work. Therefore, the >> deadlock detector was never being run. Prior to that, the next time >> any timeout was set by the backend it would re-establish it's timer. >> = >> We will of course fix our own code to prevent this issue, but I am a >> little concerned at the above commit as it reduces the robustness of >> postgres in this situation. Perhaps I will raise it on the >> pgsql-hackers list. > Hmm, so you turned off Postgres' alarms so they stopped working, and > you're saying that is a robustness issue of Postgres? If Michael's analysis were accurate, I'd agree that there is a robustness issue, but I don't think there is. See timeout.c:220: /* * Get the time remaining till the nearest pending timeout. If it= is * negative, assume that we somehow missed an interrupt, and force * signal_pending off. This gives us a chance to recover if the * kernel drops a timeout request for some reason. */ nearest_timeout =3D active_timeouts[0]->fin_time; if (now > nearest_timeout) { signal_pending =3D false; /* force an interrupt as soon as possible */ secs =3D 0; usecs =3D 1; } Now admittedly we don't have a good way to test this stanza, but it should result in re-establishing the timer interrupt the next time any timeout.c API is invoked after a missed interrupt. I don't see anything more that we could or should do. We're not going to issue setitimer() after every user-defined function call. regards, tom lane