| From: | Bryan Green <dbryan(dot)green(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | [PATCH] Fix TOCTOU races in recovery/t/020_archive_status.pl archive checks |
| Date: | 2026-08-09 03:47:26 |
| Message-ID: | a55aa303-7bb3-4855-9da2-dba9d59cc6a8@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Greetings,
recovery/t/020_archive_status.pl checks archiving progress in two separate
queries: it polls pg_stat_archiver for one condition, then asserts a related
one. For the primary it polls until archived_count is exactly 1, then
separately asserts last_archived_wal equals a specific segment; for the
always-on standby it polls until last_archived_wal equals a segment, then
asserts archived_count is exactly 2.
Both are racy. A checkpoint or crash-recovery segment archived between the
two queries pushes the count or last_archived_wal past the exact value
expected. The exact-equality poll is fragile on its own, too: if the count
jumps past the target, the poll never sees it and times out.
The fix uses monotonic >= instead of exact equality, so the checks tolerate
extra archived segments. WAL segment names sort lexically, so >= is
well defined for last_archived_wal.
--
Bryan Green
EDB: https://www.enterprisedb.com
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Fix-TOCTOU-races-in-recovery-t-020_archive_status.pl.patch | text/plain | 3.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bryan Green | 2026-08-09 03:54:51 | Re: [PATCH] Release a replication slot leaked by a caught subtransaction error |
| Previous Message | Bharath Rupireddy | 2026-08-09 03:46:30 | Re: [PATCH] Release a replication slot leaked by a caught subtransaction error |