pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Emery <postgresql@mintsoft.net>
To: pgsql-bugs@lists.postgresql.org
Subject: [PATCH] Re: BUG #16032: pg_basebackup when running on Windows doesn't clean up on failure correctly
Date: Sun, 06 Oct 2019 20:15:10 +0100
Message-ID: <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net> (raw)
In-Reply-To: <16032-4ba56823a2b2805f@postgresql.org>
References: <16032-4ba56823a2b2805f@postgresql.org>

Hello,

I've already posted this to pg_hackers, but I'm not sure if it's more 
normal to
post proposed fixes against the bug itself; so see attached if needed.

Thanks,
Rob



On 2019-10-01 17:06, PG Bug reporting form wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      16032
> Logged by:          Rob Emery
> Email address:      postgresql@mintsoft.net
> PostgreSQL version: 11.5
> Operating system:   Windows
> Description:
> 
> Hello,
> 
> When running a pg_basebackup in tar mode on windows against a PG 9.5 
> box we
> are finding that the backup doesn't get deleted successfully when it
> fails.
> Based on
> https://github.com/postgres/postgres/commit/9083353b15c3cf8e7bbac104a81ad42281178cdf#diff-473d306e41...
> we would expect it to?
> 
> To reproduce start running pg_basebackup like so:
> 
> PS C:\Users\developer> & "$PgBinPath\pg_basebackup.exe" 
> --host="PGSERVER"
> --pgdata="D:\Backups\rofl" --format=tar --wal-method=fetch
> --username="backup_user"
> 
> from a psql on the box run:
> `SELECT pg_terminate_backend(pid) FROM pg_stat_replication WHERE state 
> =
> 'backup';`
> this kills the backup.
> 
> If you run pg_basebackup on a linux box it nicely deletes the base.tar 
> and
> the directory, whereas on windows we get the following error:
> ```
> pg_basebackup: could not read COPY data: SSL SYSCALL error: EOF 
> detected
> pg_basebackup: removing data directory "D:\Backups\rofl"
> could not remove file or directory "D:\Backups\rofl/base.tar": 
> Permission
> denied
> could not remove file or directory "D:\Backups\rofl": Directory not 
> empty
> pg_basebackup: failed to remove data directory
> ```
> Once pg_basebackup has exited, the file lock seems to be gone and we 
> can
> delete it ourselves,
> it looks like pg_basebackup is contending with itself but only on 
> Windows.
> 
> We've reproduced this on 2 different Windows machines so we don't think 
> it's
> something like AntiVirus getting in the way or similiar.
> 
> Thanks,
> Rob

Attachments:

0001-Fix-bug16032-under-windows-when-the-backup-is-aborte.patch (text/x-diff, 1.5K) download From 148d525c0d30af35abba1b8c5bbe07e4e72ecfec Mon Sep 17 00:00:00 2001 From: Rob Emery <mintsoft@users.noreply.github.com> Date: Tue, 1 Oct 2019 23:51:52 +0100 Subject: [PATCH] Fix bug16032; under windows when the backup is aborted or fails, pg_basebackup is unable to cleanup the backup as the filehandles haven't been released --- src/bin/pg_basebackup/pg_basebackup.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c index aa68f59965..b6d68e0256 100644 --- a/src/bin/pg_basebackup/pg_basebackup.c +++ b/src/bin/pg_basebackup/pg_basebackup.c @@ -1098,6 +1098,17 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) { fprintf(stderr, _("%s: could not get COPY data stream: %s"), progname, PQerrorMessage(conn)); + if (strcmp(basedir, "-") != 0) + { + /* + * File handles could already be closed so we don't care about the result + */ +#ifdef HAVE_LIBZ + gzclose(ztarfile); +#else + fclose(tarfile); +#endif + } disconnect_and_exit(1); } @@ -1179,6 +1190,17 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum) { fprintf(stderr, _("%s: could not read COPY data: %s"), progname, PQerrorMessage(conn)); + if (strcmp(basedir, "-") != 0) + { + /* + * File handles could already be closed so we don't care about the result + */ +#ifdef HAVE_LIBZ + gzclose(ztarfile); +#else + fclose(tarfile); +#endif + } disconnect_and_exit(1); } -- 2.11.0

view thread (4+ messages)  latest in thread

Message-ID: <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net>
Permalink:  ../0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net/
Also on:    postgresql.org/message-id/0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: postgresql@mintsoft.net
  Subject: Re: [PATCH] Re: BUG #16032: pg_basebackup when running on Windows doesn't clean up on failure correctly
  In-Reply-To: <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net>
  References: <16032-4ba56823a2b2805f@postgresql.org> <0c6477f627e63c9cea68a6eda3f29a74@mintsoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox