Re: fix pg_mkdir_p to tolerate concurrent directory creation

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
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 14:24:03
Message-ID: 1231927.1781792643@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2026-06-18 14:32:01 Re: GRAPH_TABLE: aggregates/window/set-returning functions in COLUMNS crash the backend
Previous Message Robert Haas 2026-06-18 14:09:43 Re: pg_buffercache: Add per-relation summary stats