Re: fix pg_mkdir_p to tolerate concurrent directory creation
Andrew Dunstan <andrew@dunslane.net>
From: Andrew Dunstan <andrew@dunslane.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-06-18T15:37:49Z
Lists: pgsql-hackers
Attachments
- v2-0001-Make-pg_mkdir_p-tolerant-of-a-concurrent-director.patch (text/x-patch) patch v2-0001
On 2026-06-18 Th 10:24 AM, Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.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
Commits
-
Make pg_mkdir_p() tolerant of a concurrent directory creation.
- f25a07b2d94c 19 (unreleased) landed
- f0a831ef3e68 17 (unreleased) landed
- aa80c34c85f4 18 (unreleased) landed
- 9951e3d382c6 16 (unreleased) landed
- 4b3bc6b71453 14 (unreleased) landed
- 4647ac14230d 15 (unreleased) landed