Re: fix pg_mkdir_p to tolerate concurrent directory creation

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: fix pg_mkdir_p to tolerate concurrent directory creation
Date: 2026-06-18 15:37:49
Message-ID: 89be878a-abc1-4000-9dd2-8422d561a24b@dunslane.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2026-06-18 Th 10:24 AM, Tom Lane wrote:
> Andrew Dunstan <andrew(at)dunslane(dot)net> 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.
>
>

Oh, good catch, thanks! Here's a revised patch.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Attachment Content-Type Size
v2-0001-Make-pg_mkdir_p-tolerant-of-a-concurrent-director.patch text/x-patch 3.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeyaprakash Rajamani 2026-06-18 15:42:33 Performance Degradation (Table becomes bloat) During Repeated Bulk UPDATE Operations
Previous Message Fujii Masao 2026-06-18 15:36:06 Fix publisher-side sequence permission reporting