Re: Possible race condition in pg_mkdir_p()?

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Ning Yu <nyu(at)pivotal(dot)io>
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-30 08:04:34
Message-ID: 20190730080434.GA1644@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jul 23, 2019 at 02:54:20PM +0800, Ning Yu wrote:
> 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,

So the complains here are about two things:
- In some code paths calling mkdir, we don't care about the fact that
EEXIST can happen for something else than a folder. This could be a
problem if we have conflicts in the backend related to the naming of
the files/folders created. I find a bit surprising to not perform
the sanity checks in MakePGDirectory() in your patch. What of all the
existing callers of this routine?
- pg_mkdir_p is pretty bad at detecting problems with concurrent
creation of parent directories, leading to random failures where these
should not happen.

I may be missing something, but your patch does not actually fix
problem 2, no? Trying to do an initdb with a set of N folders using
the same parent folders not created still results in random failures.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dilip Kumar 2019-07-30 08:24:42 Re: POC: Cleaning up orphaned files using undo logs
Previous Message Andres Freund 2019-07-30 08:02:20 Re: POC: Cleaning up orphaned files using undo logs