Re: Possible race condition in pg_basebackup

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: nick ivanov <nick(at)thebeaches(dot)online>
Subject: Re: Possible race condition in pg_basebackup
Date: 2026-10-19 19:15:23
Message-ID: 179243732349.1013883.14366304306682740381.pgcf@coridan.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Nick, Andrey,

Following up on my review with the back branches (REL_15_STABLE to REL_19_STABLE, as of 2026-10-19), since the patch is marked Backpatch-through: 15.

0002 doesn't apply as is on any of them:
- in StartLogStreamer() the context line `if (!pg_parse_lsn(startpos, ...))` is `sscanf(startpos, "%X/%X", ...)` there (`"%X/%08X"` on 19), so the `param->bgconn = walconn;` hunk has to be placed by hand
- on 15, 16 and 17 CreateReplicationSlot() has no failover argument, so the new call takes 8 arguments

With only those changes it builds without warnings, src/bin/pg_basebackup's TAP tests pass, and the race (three pg_basebackup --create-slot started together, 1 MB segments, wal_keep_size = 0, a session writing WAL) gives 0 failures of 300 backups on each branch, against 150-165 of 300 without it.

0001 on 17-19 needs `#include "utils/injection_point.h"` in basebackup.c (master has it, the branches don't); on 17, INJECTION_POINT() takes one argument and Cluster.pm has no check_extension(). The free test number also differs per branch (057 on 17, 058 on 18 and 19). With that, the test passes with 0002 and fails in both modes without it on 17, 18 and 19.

The leftover slot from my previous mail isn't tied to incremental backups: with `pg_basebackup -X stream --create-slot -S leftover --manifest-checksums=bogus` the server rejects BASE_BACKUP (`unrecognized checksum algorithm: "bogus"`), and with the patch the slot stays, on every branch from 15 to 19; without it there is none.

Regards,
Pranav

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message kedar anavardekar 2026-10-19 19:46:47 Re: Fix WITHOUT OVERLAPS multirange with location replication
Previous Message surya poondla 2026-10-19 19:06:13 Re: tablecmds: Deadlock caused by Attach Partition