Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1waDf7-001cAO-2R for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 14:24:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1waDf6-00BoNK-1w for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Jun 2026 14:24:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1waDf6-00BoNA-13 for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 14:24:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1waDf4-00000000z1e-4C4T for pgsql-hackers@lists.postgresql.org; Thu, 18 Jun 2026 14:24:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 65IEO32u1231928; Thu, 18 Jun 2026 10:24:03 -0400 From: Tom Lane To: Andrew Dunstan cc: PostgreSQL Hackers Subject: Re: fix pg_mkdir_p to tolerate concurrent directory creation In-reply-to: <3ca004de-e49b-4471-b8aa-fd656e70f68c@dunslane.net> References: <3ca004de-e49b-4471-b8aa-fd656e70f68c@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Thu, 18 Jun 2026 09:18:37 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1231926.1781792643.1@sss.pgh.pa.us> Date: Thu, 18 Jun 2026 10:24:03 -0400 Message-ID: <1231927.1781792643@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Dunstan writes: > While working on the pytest stuff, I found this issue when making it > work on Windows, but the issue can exist everywhere. pg_mkdir_p can fail > if there is a concurrent directory creation. This bit: + if (errno != EEXIST || stat(path, &sb) != 0 || !S_ISDIR(sb.st_mode)) + { + retval = -1; + break; + } looks like it could corrupt the reported errno, ie stat() could overwrite what mkdir() reported. regards, tom lane