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 1o7Ilm-0008Ey-9R for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 15:41:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o7Ilj-0003O8-98 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jul 2022 15:41:19 +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 1o7Ili-0003Nz-Vv for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 15:41:18 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7Ilc-00081b-0i for pgsql-hackers@lists.postgresql.org; Fri, 01 Jul 2022 15:41:18 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 9ABFA32002FB for ; Fri, 1 Jul 2022 11:41:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 01 Jul 2022 11:41:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1656690069; x=1656776469; bh=djtGH3dIb9JXFOEp++YHy+Vtqi+4 Z4GG9ssfA+S0NbU=; b=BTL6ulpLw57HQ0FOJ6Sru5Lfzke5JV2sG2PAeGdtOKMr qjqZeknJUZkZzHtuHilQycBTMnYLcw+XLv3UvGQAh6w1UGuPZrWR8bRifLBEF8Py 67/l6B2GqG8ZT2hmATPqiRUAOLGSayNj7clr0es0hA7W09HhqG4O7BeYMv6VzlXS 23cK973hWjbz4o8bDv+eSnFTt+AgcjCeEMMsjf2U6dnVYQDah18Wgom8IDexb0pq lJxqadZ8z0Troz6rKgrR+jcL4RgbZf2Xgq/bQXaKn+NGt8+hJynJvCuWLsnQ2Y55 G4L0Ajqx6g3041kbg341VUH0hIIRGJPxvrdCQ6ed3w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudehfedgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfesmhekreertddtjeenucfhrhhomheptehlvhgrrhho ucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgheqne cuggftrfgrthhtvghrnhepkeeitdekteeffefgudfhjeehieevffeggfetudeiheejffel hffhfeehleeghfetnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghdpvghnth gvrhhprhhishgvuggsrdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 1 Jul 2022 11:41:08 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id A3D5836A; Fri, 1 Jul 2022 17:41:05 +0200 (CEST) Date: Fri, 1 Jul 2022 17:41:05 +0200 From: Alvaro Herrera To: Pg Hackers Subject: EINTR in ftruncate() Message-ID: <20220701154105.jjfutmngoedgiad3@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="knr42z5qyvhth5as" Content-Disposition: inline Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --knr42z5qyvhth5as Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit Nicola Contu reported two years ago to pgsql-general[1] that they were having sporadic query failures, because EINTR is reported on some system call. I have been told that the problem persists, though it is very infrequent. I propose the attached patch. Kyotaro proposed a slightly different patch which also protects write(), but I think that's not necessary. Thomas M. produced some more obscure theories for other things that could fail, but I think we should patch this problem first, which seems the most obvious one, and deal with others if and when they are reported. [1] https://www.postgresql.org/message-id/CAMTZZh2V%2B0wJVgSqTVvXUAVMduF57Uxubvvw58%3DkbOae%2B53%2BQQ%40mail.gmail.com -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Use it up, wear it out, make it do, or do without" --knr42z5qyvhth5as Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-retry-ftruncate.patch" From 466ed63b9b399c2914aa44f56f56e044341a77f5 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Fri, 1 Jul 2022 17:16:33 +0200 Subject: [PATCH v2] retry ftruncate --- src/backend/storage/ipc/dsm_impl.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/backend/storage/ipc/dsm_impl.c b/src/backend/storage/ipc/dsm_impl.c index 873867e856..4f35e7e3d1 100644 --- a/src/backend/storage/ipc/dsm_impl.c +++ b/src/backend/storage/ipc/dsm_impl.c @@ -362,8 +362,21 @@ dsm_impl_posix_resize(int fd, off_t size) { int rc; - /* Truncate (or extend) the file to the requested size. */ - rc = ftruncate(fd, size); + /* + * Truncate (or extend) the file to the requested size. We may get + * interrupted. If so, just retry unless there is an interrupt pending. + * This avoids the possibility of looping forever if another backend is + * repeatedly trying to interrupt us. + */ + for (;;) + { + errno = 0; + rc = ftruncate(fd, size); + if (rc == 0) + break; + if (errno != EINTR || ProcDiePending || QueryCancelPending) + return rc; + } /* * On Linux, a shm_open fd is backed by a tmpfs file. After resizing with -- 2.30.2 --knr42z5qyvhth5as--