Re: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures - Mailing list pgsql-hackers

From Xuneng Zhou
Subject Re: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures
Date
Msg-id CABPTF7WPBe4te-mzhZ3gs-iNHj+YPdTWuwaZH=63bkmO5pA+9g@mail.gmail.com
Whole thread
In response to Re: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures  (Alexander Korotkov <aekorotkov@gmail.com>)
Responses Re: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures
List pgsql-hackers
On Thu, Apr 9, 2026 at 2:00 PM Alexander Korotkov <aekorotkov@gmail.com> wrote:
>
> Hi, Satya!
>
> On Thu, Apr 9, 2026 at 5:03 AM SATYANARAYANA NARLAPURAM
> <satyanarlapuram@gmail.com> wrote:
> > An assertion failure (server crash in assert-enabled builds) occurs when WAIT FOR LSN ... INTO is used inside
PL/pgSQLDO 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.
>
> Thank you for reporting.  But I doubt the fix is correct.  Even that
> this particular might work OK, I don't think it's safe to release
> snapshots belonging to functions/procedures: it might affect them.  I
> tend to think we must forbid wrapping WAIT FOR LSN with
> functions/procedures.  I'll explore more on this today.
>


--
Best,
Xuneng



pgsql-hackers by date:

Previous
From: Mohamed ALi
Date:
Subject: [PATCH] Fix: Partitioned parent index remains invalid after child indexes are repaired
Next
From: Lakshmi N
Date:
Subject: Re: DOCS: pg_plan_advice minor doc fixes