Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures
SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
From: SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com>
To: Alexander Korotkov <aekorotkov@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-04-09T02:03:31Z
Lists: pgsql-hackers
Attachments
- 0002-Add-regression-tests-for-WAIT-FOR-LSN-inside-PL-pgSQ.patch (application/octet-stream) patch v1-0002
- 0001-Fix-assertion-failure-in-WAIT-FOR-LSN-when-used-insi.patch (application/octet-stream) patch v1-0001
Hi hackers, Alexander,
An assertion failure (server crash in assert-enabled builds) occurs when
WAIT FOR LSN ... INTO is used inside PL/pgSQL DO blocks or within void
procedures.
Repro:
-- Run this on a standby
CREATE PROCEDURE test_wait()
LANGUAGE plpgsql AS $$
DECLARE
result text;
BEGIN
WAIT FOR LSN '0/1234' INTO result;
RAISE NOTICE '%', result;
END;
$$;
CALL test_wait();
The WAIT FOR itself succeeds, but the very next PL/pgSQL statement that
requires a snapshot crashes the backend with:
TRAP: failed Assert("portal->portalSnapshot == NULL"),
File: "pquery.c", Line: 1776
Attached patches for both the test case and a potential fix. Please review.
Thanks,
Satya
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Explicitly forbid non-top-level WAIT FOR execution
- a8b61c23c5ff 19 (unreleased) landed