Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n30eo-0002qT-L4 for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Dec 2021 19:00:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1n30el-0001Mp-23 for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Dec 2021 19:00:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n30ek-0001Mg-OO for pgsql-bugs@lists.postgresql.org; Thu, 30 Dec 2021 19:00:06 +0000 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n30ei-0005Qu-Gw for pgsql-bugs@lists.postgresql.org; Thu, 30 Dec 2021 19:00:05 +0000 Received: by mail-lf1-x130.google.com with SMTP id u13so56113910lff.12 for ; Thu, 30 Dec 2021 11:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=hjUJw08qrqTTplf/MtDhIdOmXmRkTnKKCCwxdUQbMQw=; b=ZoEwUVv57u6kqhaecxQa+MXi+M/QT+oskKoBWvE6VB2LII5UF/c2BbuBV6DzG0QU/T mgLEr1Q3xyPJKbXnhwOMC6TxFV2VhEIDo3xquiLamnnXnZopR6jQzbTy8h7YR729CBbH +mkBWw78Aj+dUlVn5Pn3TAMxxvJavIeo7XfzSRrQJZMQ7Ub96O6RGjbzxd1eBnnHIj+/ zTaetHZMKwuTFfOtbynkTVzk7obh5N1Q4vAa2Pwj07fjsTyG8MjsyMBr5K681QAUXe5H H4Oy7O6kjzw5TKS3F1snNhtzZynebqsOfhEXEM+HLEGlM2UfgiDsrPEoO4PwdZoXeLb9 w/7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=hjUJw08qrqTTplf/MtDhIdOmXmRkTnKKCCwxdUQbMQw=; b=d0Umq1amBbwdtTseuePfXeeJOoiVcJG6CYwfYKojDmPY9m4UeoU5ATSlObOW2HgTo5 VBsAlyv+qkYym4vf4dotz3C7ZwvIryWykr+0KPaasrtPGp+KYFavzJr1wAyFWTYNuGeQ 9jibHe0JaCxfPPxjtowbqfCyzdGR/OCHOJVg5TQSzc4Qut/53UyYChwPjmkhT5GCTwfT 85JM1pgf/E+obc5RUDsyf3nXRQDKDSB7d5MEAXfCvMtqrLxAgfLd+UQctpcYxGYWitiM aB4VtXGzKOQqy1OVznjMA5fKhlMTjtTZG3Gzz1TKyNKyGFGOVUAcrleUGqaUIItX2GE+ g+UQ== X-Gm-Message-State: AOAM532aF0wLug4m36Q+waqEVdGAbM8gdxt2dKxpbYL9vUCWlSd3UE8P /5BQBYxg9NZ7v8JtbMQQ0pfkXM56OAg= X-Google-Smtp-Source: ABdhPJxK8ZUGKa/dLd7LuEBr+QRdVmn8AxTNxJdQjOaN4gH/p7WFcOP7kCF7ln+Fyl5/Uwb7uVUU9Q== X-Received: by 2002:a05:6512:114e:: with SMTP id m14mr26802381lfg.414.1640890802754; Thu, 30 Dec 2021 11:00:02 -0800 (PST) Received: from [1.0.0.7] ([178.155.6.153]) by smtp.gmail.com with ESMTPSA id h1sm2118191ljo.134.2021.12.30.11.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Dec 2021 11:00:02 -0800 (PST) Subject: Re: BUG #17284: Assert failed in SerialAdd() when the summarize_serial mode is engaged To: pgsql-bugs@lists.postgresql.org References: <17284-c878f548184aae1f@postgresql.org> From: Alexander Lakhin Message-ID: Date: Thu, 30 Dec 2021 22:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <17284-c878f548184aae1f@postgresql.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello hackers, 13.11.2021 15:00, PG Bug reporting form wrote: > When running concurrent installchecks (x100) for src/test/isolation, I've > observed the following server crash: > Core was generated by `postgres: postgres regress30 127.0.0.1(55840) SEL'. > Program terminated with signal SIGABRT, Aborted. > #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 > 50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. > (gdb) bt > #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 > #1 0x00007fd1b69d5535 in __GI_abort () at abort.c:79 > #2 0x000055d441cc3a02 in ExceptionalCondition ( > conditionName=conditionName@entry=0x55d441e34cd2 > "TransactionIdIsValid(tailXid)", > errorType=errorType@entry=0x55d441d1c01d "FailedAssertion", > fileName=fileName@entry=0x55d441e34bc9 "predicate.c", > lineNumber=lineNumber@entry=928) at assert.c:67 > #3 0x000055d441b8e0aa in SerialAdd > (minConflictCommitSeqNo=18446744073709551615, xid=95552353) at > predicate.c:928 The issue is reproduced (on REL_14_STABLE) with the following command sequence (can be replayed with pgreplay): 2021-12-29 18:00:15.000 MSK|postgres|regression|61cc77ff.18af00|LOG:  statement:      create table D1 (id int not null);      create table D2 (id int not null);      insert into D1 values (1);      insert into D2 values (1); 2021-12-29 18:00:15.100 MSK|postgres|regression|61cc77ff.18af00|LOG:  disconnection: session time: 0:00:01.129 user=postgres database=regression host=127.0.0.1 port=46730 2021-12-29 18:00:15.200 MSK|postgres|regression|61cc77ff.18af01|LOG:  statement: begin isolation level serializable; 2021-12-29 18:00:15.300 MSK|postgres|regression|61cc77ff.18af02|LOG:  statement: begin isolation level serializable; 2021-12-29 18:00:15.400 MSK|postgres|regression|61cc77ff.18af02|LOG:  statement: update D2 set id = id + 1; 2021-12-29 18:00:15.500 MSK|postgres|regression|61cc77ff.18af02|LOG:  statement: commit; 2021-12-29 18:00:15.600 MSK|postgres|regression|61cc77ff.18af03|LOG:  statement: begin isolation level serializable; 2021-12-29 18:00:15.700 MSK|postgres|regression|61cc77ff.18af01|LOG:  statement: update D1 set id = id + 1; 2021-12-29 18:00:15.800 MSK|postgres|regression|61cc77ff.18af03|LOG:  statement: select id from D1; 2021-12-29 18:00:15.800 MSK|postgres|regression|61cc77ff.18af01|LOG:  disconnection: session time: 0:00:01.000 user=postgres database=regression host=127.0.0.1 port=46731 2021-12-29 18:00:15.900 MSK|postgres|regression|61cc77ff.18af02|LOG:  statement: select pg_sleep(1); To ease a reproduction, the following delays can be added to predicate.c: @@ -1502,6 +1507,7 @@ SummarizeOldestCommittedSxact(void)  {         SERIALIZABLEXACT *sxact;   +       pg_usleep(1000000);         LWLockAcquire(SerializableFinishedListLock, LW_EXCLUSIVE);           /* @@ -3745,6 +3760,7 @@ ClearOldPredicateLocks(void)         SERIALIZABLEXACT *finishedSxact;         PREDICATELOCK *predlock;   +       pg_usleep(2000000);         /*          * Loop through finished transactions. They are in commit order, so we can          * stop as soon as we find one that's still interesting. With these delays and CPPFLAGS="-DTEST_SUMMARIZE_SERIAL" the assertion failure can be observed just on `make check`. As I can see, on disconnect of session 18af01 the ReleasePredicateLocks() function calls SetNewSxactGlobalXmin() where SerialSetActiveSerXmin(called with PredXact->SxactGlobalXmin == InvalidTransactionId) sets serialControl->tailXid to InvalidTransactionId. Then session 18af03 calls SummarizeOldestCommittedSxact(), that in case !SHMQueueEmpty(FinishedSerializableTransactions) calls SerialAdd() where the check TransactionIdIsValid(serialControl->tailXid) fails. But if ReleasePredicateLocks() in session 18af01 happens to reach ReleasePredicateLocks(), the FinishedSerializableTransactions queue gets empty, and it would prevent calling SerialAdd() in session 18af03. So there is a small window (that probably can be widened by LWLockAcquire()) between             SetNewSxactGlobalXmin();             needToClear = true; and     if (needToClear)         ClearOldPredicateLocks(); where a concurrent transaction can fail in SummarizeOldestCommittedSxact(). Best regards, Alexander