Re: Possible race condition in pg_mkdir_p()? - Mailing list pgsql-hackers

From Ning Yu
Subject Re: Possible race condition in pg_mkdir_p()?
Date
Msg-id CAKmaiL1XcFKuzVCqkuHP0Le1z8tk0xntXGkN2H35rE24Ukcuig@mail.gmail.com
Whole thread Raw
In response to Re: Possible race condition in pg_mkdir_p()?  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Possible race condition in pg_mkdir_p()?  (Michael Paquier <michael@paquier.xyz>)
List pgsql-hackers
Hi Michael,

The patches are attached.  To make reviewing easier we spilt them into small
pieces:

- v1-0001-Fix-race-condition-in-pg_mkdir_p.patch: the fix to pg_mkdir_p()
  itself, basically we are following the `mkdir -p` logic;
- v1-0002-Test-concurrent-call-to-pg_mkdir_p.patch: the tests for pg_mkdir_p(),
  we could see how it fails by reverting the first patch, and a reproducer with
  initdb is also provided in the README; as we do not know how to create a unit
  test in postgresql we have to employ a test module to do the job, not sure if
  this is a proper solution;
- v1-0003-Fix-callers-of-pg_mkdir_p.patch &
  v1-0004-Fix-callers-of-MakePGDirectory.patch: fix callers of pg_mkdir_p() and
  MakePGDirectory(), tests are not provided for these changes;

MakePGDirectory() is also called in TablespaceCreateDbspace(), EEXIST is
considered as non-error for parent directories, however as it considers EEXIST
as a failure for the last level of the path so the logic is still correct, we
do not add a final stat() check for it.

Best Regards
Ning


On Thu, Jul 18, 2019 at 4:57 PM Michael Paquier <michael@paquier.xyz> wrote:
On Thu, Jul 18, 2019 at 04:17:22PM +0800, Ning Yu wrote:
> This is still wrong with current code logic, because when the statusdir is
> a file the errno is also EEXIST, but it can pass the check here.  Even if
> we fix pg_mkdir_p() by following the `mkdir -p` way the errno check here is
> still wrong.

Would you like to send a patch?
--
Michael
Attachment

pgsql-hackers by date:

Previous
From: Noah Misch
Date:
Subject: Re: Race conditions with TAP test for syncrep
Next
From: Wh isere
Date:
Subject: query1 followed by query2 at maximum distance vs current fixed distance