[BUG] failed assertion in EnsurePortalSnapshotExists()

From: "Drouvot, Bertrand" <bdrouvot(at)amazon(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [BUG] failed assertion in EnsurePortalSnapshotExists()
Date: 2021-09-27 15:52:25
Message-ID: ff82b8c5-77f4-3fe7-6028-fcf3303e82dd@amazon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

I recently observed a failed assertion in EnsurePortalSnapshotExists().

The steps to reproduce the issue on the master branch are:

create table bdt (a int primary key);
insert into bdt values (1),(2);
create table bdt2 (a int);
insert into bdt2 values (1);

Then launching:

DO $$
BEGIN
  FOR i IN 1..2 LOOP
    BEGIN
      INSERT INTO bdt (a) VALUES (i);
       exception when unique_violation then update bdt2 set a = i;
     COMMIT;
    END;
  END LOOP;
END;
$$;

Would produce:

server closed the connection unexpectedly
        This probably means the server terminated abnormally
        before or while processing the request.
The connection to the server was lost

Due to:

#2  0x0000000000b2ffcb in ExceptionalCondition (conditionName=0xd0d598
"portal->portalSnapshot == NULL", errorType=0xd0d0b3 "FailedAssertion",
fileName=0xd0d174 "pquery.c", lineNumber=1785) at assert.c:69
#3  0x000000000099e666 in EnsurePortalSnapshotExists () at pquery.c:1785

From what i have seen, we end up having ActiveSnapshot set to NULL in
AtSubAbort_Snapshot() (while we still have ActivePortal->portalSnapshot
not being NULL and not set to NULL later on).

That leads to ActiveSnapshotSet() not being true in the next call to
EnsurePortalSnapshotExists() and leads to the failed assertion (checking
that ActivePortal->portalSnapshot is NULL) later on in the code.

Based on this, i have created the attached patch (which fixes the issue
mentioned in the repro) but I have the feeling that I may have missed
something more important here (that would not be addressed with the
attached patch), thoughts?

Thanks

Bertrand

Attachment Content-Type Size
v1-0001-EnsurePortalSnapshotExists-failed-assertion.patch text/plain 580 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2021-09-27 16:17:14 Re: when the startup process doesn't (logging startup delays)
Previous Message Robert Haas 2021-09-27 15:49:59 Re: when the startup process doesn't (logging startup delays)