Re: fix pg_mkdir_p to tolerate concurrent directory creation

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Dunstan <andrew@dunslane.net>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-06-18T14:24:03Z
Lists: pgsql-hackers
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



Commits

  1. Make pg_mkdir_p() tolerant of a concurrent directory creation.