pgsql: Fix timeout overflow in WAIT FOR LSN

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix timeout overflow in WAIT FOR LSN
Date: 2026-09-14 11:49:53
Message-ID: E1x65C5-00000000HMh-2qXo@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix timeout overflow in WAIT FOR LSN

Commit 447aae13b03 accepted TIMEOUT values up to INT64_MAX
milliseconds, but computing the deadline multiplies by 1000, which
caused an int64 overflow. And the command reported a timeout at once
instead of waiting.

Parse the value as an int instead, which simplifies the code and is
consistent with other timeout values such as the statement_timeout GUC.

The specified values are now rounded to the nearest millisecond, so a
positive timeout below half a millisecond becomes zero and waits
indefinitely.

Backpatch to v19, where the TIMEOUT option was introduced.

Reported-by: ChangAo Chen <cca5507(at)qq(dot)com>
Author: ChangAo Chen <cca5507(at)qq(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Reviewed-by: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Discussion: https://postgr.es/m/tencent_86B83240785807077600A1778566B5C12908@qq.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6c44473c2deed07b4cca3c202dd48b1e8e002ec9

Modified Files
--------------
doc/src/sgml/ref/wait_for.sgml | 18 +++++++++++++-----
src/backend/access/transam/xlogwait.c | 2 +-
src/backend/commands/repack_worker.c | 4 ++--
src/backend/commands/wait.c | 32 +++++++-------------------------
src/include/access/xlogwait.h | 2 +-
src/test/recovery/t/049_wait_for_lsn.pl | 14 ++++++++++++++
6 files changed, 38 insertions(+), 34 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-09-14 11:50:05 pgsql: Fix timeout overflow in WAIT FOR LSN
Previous Message Etsuro Fujita 2026-09-14 10:04:07 pgsql: postgres_fdw: Disable attribute statistics import from pre-9.1 s