From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Dunstan <andrew@dunslane.net>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: fix pg_mkdir_p to tolerate concurrent directory creation
Date: Thu, 18 Jun 2026 10:24:03 -0400
Message-ID: <1231927.1781792643@sss.pgh.pa.us> (raw)
In-Reply-To: <3ca004de-e49b-4471-b8aa-fd656e70f68c@dunslane.net>
References: <3ca004de-e49b-4471-b8aa-fd656e70f68c@dunslane.net>
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.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, andrew@dunslane.net, pgsql-hackers@lists.postgresql.org
Subject: Re: fix pg_mkdir_p to tolerate concurrent directory creation
In-Reply-To: <1231927.1781792643@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox