Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAx4c-000bGw-0l for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 21:38:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAx4Y-007qZR-1g for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 21:37:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wAx4Y-007qZI-0J for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2026 21:37:59 +0000 Received: from mail-vs1-xe2d.google.com ([2607:f8b0:4864:20::e2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAx4W-00000000EAj-1xEy for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2026 21:37:58 +0000 Received: by mail-vs1-xe2d.google.com with SMTP id ada2fe7eead31-605b3b6c4dcso846527137.1 for ; Thu, 09 Apr 2026 14:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775770676; cv=none; d=google.com; s=arc-20240605; b=jPaEYtQpUC3WxObDXbDAdj+/HOmzdx+E8XBdgsvaGcH1bp2hasO33ZrlnkaWo368Vk YEEFDaiAzAE2C0t31wnzpQhJiFzFDoWB3A86Ey2y1n7DZgBJU2pS8z7ZNSYeasR8T0+u eH79N7RvzvQJ1fWWhm7fFymIGfI30Xm2tFz8Vc1Ww9uhsa3fXVn7JZAJLEI40bW4YFHI Js7/70J4ZVlyidgwlaNGCHyyoshDNsBzMMaZsJ22fSgZjHOaRmCxjBG9EWM0kyyKtY9d 46+KTP56IPgTN+AX4d1txPQXyQpcXrcpQy6UHRQt/hegpvDzur9uuj/cW1khehyIEax3 dIMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=vEyzBno5P/y/OG8geJIogPmz9pYmOrDSclAtNIUTMtQ=; fh=AEn94vVuaVDPL1tB+86CCZZ+VgMW/1jGuhJ1FfBOHcs=; b=UcL++YvnQrj8DlPDCfSX/GQplEI1IJuCgyUtN/pg+cAEYGlCaOxiyA8SDjl/9oKeR/ x9bjCf4nBKz/XuSdjr+DTSCWYIwcDM0gbYp3rj5j4dhLqUyONfeQ7gVlaTSoRQS6fipm 14aWauDEHa895SmGYKc2M2BVhXBBStHB+IVGKozVqmaCIBFs2R7Y604nWCidtTNRXkK6 CBeYN0Jh+Woawic2URoKR6WGaZjYeM0NRVIU1JMawWOTm0v9vge8VAKqqVQW3Px+TWOm /a5tDlrU0lz9Z5wileJhVbLZOKfjf0iOeThjy2W38gykfF9ajK1Msq8XGdNQNa1pnBZh 2TlQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775770676; x=1776375476; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=vEyzBno5P/y/OG8geJIogPmz9pYmOrDSclAtNIUTMtQ=; b=WFE4GAE47mrGzFJMzyteg8gFBU0CnL5iBSS4imDjq6f+LHe6frqK8uoEUCys63CyxP TDn6Cptgl6STQMqSPwAFZazi+k9oZgrotHQFlLg69iSomlAIxUb7vpe6Bugnw9VZXtYW 8d68TSYVkktYsPhGrNAqzZMsEb5sUoJI1Ldoqvp9kZII7mXHrHJAzbFlxKz2X3QI7zdG LCjz4aGX9yhpWiLWgq7eK45PdTqVMaWnpcZIlNkSSdZo9PBAk5M8lHzPuGAf++cUJi4p 7gK9816rBade5i4iZTEZ/0J3/xaCmI9VFIpI9UDci+SiaLmVn/5l0fXCIkCxf9Fj2VfD lUtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775770676; x=1776375476; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vEyzBno5P/y/OG8geJIogPmz9pYmOrDSclAtNIUTMtQ=; b=Aauc/ziWJbg9wX7Y37g/zydcA8z0Jt3HgdXHmnkzcDdOoeAGNPSCcMhdzvH8ZwL6e4 uZiA2geHDnge0mNVOwV3V4otZ9TOKuc59x45IU8wQMBOJZLVfefYgryc5gZWIuuBsxnu tA2/c7tVDQfK7sMc64++spYXDmBVKj8BH0tc4jTQqZJai4tGEzCxPFPJYwJhdPVmqE8X TM9FFGZ3aABKeGrkl4Q5VlWrPnJw9Rqb+SPt2ro14ns753em1dEqGal2xu+va41ftUr9 1ndi+iZ+6LDJB65xzQgPz4/bGEUcgIXNKy05zGfvx6JUKXYj/oSm66Vo9vub1Sb73uiv ogRw== X-Gm-Message-State: AOJu0YzrZutJfaxHp4spYF0ij2MFo/3ySry4SzD9qTk/UT+YQUSBe1jC wz5gf4iQdRtig5YdlD1z+Sdu1Z18duaKIKiG867DQl6YrEZj4h0Dh6AH8A5w7xMAVIXWX03uJE4 rRk86xXUZP3ajqF6ap6X+nAjnuPJ8yEk= X-Gm-Gg: AeBDievk2ysNdYrwL0SH71+/fzmYWYYuY/BQedHoiAvZP5C8pIyeLjnGwOM36nE22Q4 bzLUmcKVL8J0OtSmfmbB3XozL6CXP45K8Yy/uk4KlOIULNH/06BsCUOBXrf0lvVwjB4fv8Blof9 nXrZkRKjKPItl+Pn+V16IaGzZ8jIaSFYfTFlw26XDkImjrwL5MInrd71VOAoVgjliXHKoeVZA/d +Qmj2XwshuyjRogQ0/3P52PNDip2JL6GUFFkxsKtwqhmgry5E1XnJ3pFoSJV69guGApi2TNg3UB 3G0k01cVuZX8UC2TX97ugwNQcLk1hQBfG5UV X-Received: by 2002:a05:6102:ccb:b0:5ff:ea89:449a with SMTP id ada2fe7eead31-608705a7d17mr2008679137.13.1775770676106; Thu, 09 Apr 2026 14:37:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: SATYANARAYANA NARLAPURAM Date: Thu, 9 Apr 2026 14:37:44 -0700 X-Gm-Features: AQROBzDXfNx_D3kMqdKV71FPkg6aKYz5uZiuIpvbWoT3dVXNvGEzxPttLmKYP10 Message-ID: Subject: Re: Bug: WAIT FOR LSN crashes with assertion failure inside PL/pgSQL DO blocks and procedures To: Alexander Korotkov Cc: PostgreSQL Hackers , PostgreSQL-development Content-Type: multipart/alternative; boundary="0000000000005a1b54064f0dd46d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005a1b54064f0dd46d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Alexander, On Thu, Apr 9, 2026 at 5:28=E2=80=AFAM Alexander Korotkov wrote: > On Thu, Apr 9, 2026 at 10:27=E2=80=AFAM SATYANARAYANA NARLAPURAM > wrote: > > On Wed, Apr 8, 2026 at 11:00=E2=80=AFPM Alexander Korotkov > wrote: > >> On Thu, Apr 9, 2026 at 5:03=E2=80=AFAM SATYANARAYANA NARLAPURAM > >> wrote: > >> > An assertion failure (server crash in assert-enabled builds) occurs > when WAIT FOR LSN ... INTO is used inside PL/pgSQL DO blocks or within vo= id > 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 =3D=3D 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. > > > > > > Agreed, attached a v2 patch with your suggestion on preventing it runni= ng > > from procedures. > > Thank you. I've slightly revised your patch. I'm going to push it if > no objections. > LGTM, thank you! --0000000000005a1b54064f0dd46d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Alexander,

On Thu= , Apr 9, 2026 at 5:28=E2=80=AFAM Alexander Korotkov <aekorotkov@gmail.com> wrote:
On Thu, Apr 9, 2026 at 10:27=E2=80= =AFAM SATYANARAYANA NARLAPURAM
<satyanar= lapuram@gmail.com> wrote:
> On Wed, Apr 8, 2026 at 11:00=E2=80=AFPM Alexander Korotkov <aekorotkov@gmail.com= > wrote:
>> On Thu, Apr 9, 2026 at 5:03=E2=80=AFAM 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/pgSQL DO blocks or with= in void procedures.
>> >
>> > Repro:
>> >
>> > -- Run this on a standby
>> >
>> > CREATE PROCEDURE test_wait()
>> >=C2=A0 =C2=A0LANGUAGE plpgsql AS $$
>> >=C2=A0 =C2=A0DECLARE
>> >=C2=A0 =C2=A0 =C2=A0result text;
>> >=C2=A0 =C2=A0BEGIN
>> >=C2=A0 =C2=A0 =C2=A0WAIT FOR LSN '0/1234' INTO result;=
>> >=C2=A0 =C2=A0 =C2=A0RAISE NOTICE '%', result;
>> >=C2=A0 =C2=A0END;
>> >=C2=A0 =C2=A0$$;
>> >=C2=A0 =C2=A0CALL test_wait();
>> >
>> >
>> > The WAIT FOR itself succeeds, but the very next PL/pgSQL stat= ement that requires a snapshot crashes the backend with:
>> >
>> >=C2=A0 =C2=A0TRAP: failed Assert("portal->portalSnapsh= ot =3D=3D NULL"),
>> >=C2=A0 =C2=A0File: "pquery.c", Line: 1776
>> >
>> > Attached patches for both the test case and a potential fix. = Please review.
>>
>> Thank you for reporting.=C2=A0 But I doubt the fix is correct.=C2= =A0 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.= =C2=A0 I
>> tend to think we must forbid wrapping WAIT FOR LSN with
>> functions/procedures.=C2=A0 I'll explore more on this today. >
>
> Agreed, attached a v2 patch with your suggestion on preventing it runn= ing
> from procedures.

Thank you.=C2=A0 I've slightly revised your patch.=C2=A0 I'm going = to push it if
no objections.

LGTM, thank you!=C2=A0
--0000000000005a1b54064f0dd46d--