Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHVJW-0001gd-Sp for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Oct 2019 15:52:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iHVJV-0007Fo-KT for pgsql-bugs@arkaria.postgresql.org; Mon, 07 Oct 2019 15:52:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iHVJV-0007Fh-9Z for pgsql-bugs@lists.postgresql.org; Mon, 07 Oct 2019 15:52:45 +0000 Received: from anput.mintsoft.net ([130.255.76.212]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1iHVJT-0005hZ-40 for pgsql-bugs@lists.postgresql.org; Mon, 07 Oct 2019 15:52:44 +0000 Received: from set.mintsoft.net (cpc89770-stok19-2-0-cust16356.1-4.cable.virginm.net [86.23.127.229]) by anput.mintsoft.net (Postfix) with ESMTPS id 1A871432B4; Mon, 7 Oct 2019 15:52:42 +0000 (UTC) Received: by set.mintsoft.net (Postfix, from userid 33) id A9A331010AB; Mon, 7 Oct 2019 16:52:41 +0100 (BST) To: Michael Paquier Subject: Re: [PATCH] Re: BUG #16032: pg_basebackup when running on Windows doesn't clean up on failure correctly X-PHP-Originating-Script: 1000:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 07 Oct 2019 16:52:41 +0100 From: Rob Emery Cc: pgsql-bugs@lists.postgresql.org In-Reply-To: <20191007012132.GE14532@paquier.xyz> References: <16032-4ba56823a2b2805f@postgresql.org> <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net> <20191007012132.GE14532@paquier.xyz> Message-ID: <8b5a4cd5812e2ec1e22ae1d9cc370ab2@mintsoft.net> X-Sender: postgresql@mintsoft.net User-Agent: Roundcube Webmail/1.2.2 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hiya Michael, > Regarding your patch, anything living in the middle of processing > (basically calling disconnect_and_exit() in ~11 and exit() for 12~) > would fail into this category. Wouldn't it make sense here to use > atexit() to ensure that the cleanup always happens? I am not sure > that it is a good idea to hope that anything processing the base > backup COPY chunks will remember to clean up those handles in the > event of an error. I am ready to bet that any future code will forget > to add that so we would keep falling into the same trap. Yes and no, the problem is that under Windows the file cleanup occurs before the process itself actually ends, as the streaming of the backup from the COPY is performed in a thread, not a fork. So, if we attempt to use atexit to cleanup the filehandles, pg_basebackup will still be attempting to delete the partial backup before the file handles are cleaned up by the atexit callback. I hope that makes sense; I agree with your sentiment that there must be a better way of structuring this. -Rob