Re: Possible race condition in pg_mkdir_p()?

From: Ning Yu <nyu(at)pivotal(dot)io>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>, Paul Guo <pguo(at)pivotal(dot)io>
Subject: Re: Possible race condition in pg_mkdir_p()?
Date: 2019-07-23 06:54:20
Message-ID: CAKmaiL1XcFKuzVCqkuHP0Le1z8tk0xntXGkN2H35rE24Ukcuig@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)paquier(dot)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 Content-Type Size
v1-0003-Fix-callers-of-pg_mkdir_p.patch application/octet-stream 1.2 KB
v1-0004-Fix-callers-of-MakePGDirectory.patch application/octet-stream 1.7 KB
v1-0002-Test-concurrent-call-to-pg_mkdir_p.patch application/octet-stream 10.0 KB
v1-0001-Fix-race-condition-in-pg_mkdir_p.patch application/octet-stream 2.1 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Wh isere 2019-07-23 06:55:44 query1 followed by query2 at maximum distance vs current fixed distance
Previous Message Noah Misch 2019-07-23 06:45:53 Re: Race conditions with TAP test for syncrep