Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eYE1t-0002p7-Ci for pgsql-committers@arkaria.postgresql.org; Sun, 07 Jan 2018 16:42:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eYE1s-0001jh-HP for pgsql-committers@arkaria.postgresql.org; Sun, 07 Jan 2018 16:42:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eYE1s-0001jX-0X for pgsql-committers@lists.postgresql.org; Sun, 07 Jan 2018 16:42:36 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eYE1l-0007la-IF for pgsql-committers@postgresql.org; Sun, 07 Jan 2018 16:42:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w07GgQN7017684; Sun, 7 Jan 2018 11:42:26 -0500 From: Tom Lane To: Thomas Munro cc: pgsql-committers Subject: Re: pgsql: Improve error handling in RemovePgTempFiles(). In-reply-to: References: Comments: In-reply-to Thomas Munro message dated "Sun, 07 Jan 2018 16:47:56 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17682.1515343346.1@sss.pgh.pa.us> Date: Sun, 07 Jan 2018 11:42:26 -0500 Message-ID: <17683.1515343346@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > Perhaps RemovePgTempFiles() could check if each one exists before > calling RemovePgTempFilesInDir(), like in the attached? Alternatively > we could make RemovePgTempFilesInDir() return early if temp_dir == > NULL (going against your commit message above), or I suppose we could > arrange for temporary directories always to exist in base and each > tablespace. After further thought I don't especially like your solution as written: it has a race condition if the directory is deleted between the pre-check and the AllocateDir proper. What seems better to me is a tighter version of your second alternative: let's add a "missing_ok" parameter to RemovePgTempFilesInDir, which'd be passed as true only at the top level, and do something like temp_dir = AllocateDir(tmpdirname); + if (temp_dir == NULL && errno == ENOENT && missing_ok) + return; + while ((temp_de = ReadDirExtended(temp_dir, tmpdirname, LOG)) != NULL) This might be problematic if RemovePgTempFilesInDir were a globally exposed API, but it isn't, so adding a parameter seems fine. Hmmm ... actually, in the recursive call case, it wouldn't be that awful to ignore ENOENT either; if a directory goes away between being stat'd and being opened, you'd still get a log message about rmdir failure at the caller level. So maybe we should just do your second alternative as-is (ie, code as above but without missing_ok). Having an explicit control parameter seems marginally clearer but I'm not sure it's buying anything meaningful. Thoughts? regards, tom lane