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.94.2) (envelope-from ) id 1s5PrB-005Hsw-Hr for pgsql-hackers@arkaria.postgresql.org; Fri, 10 May 2024 13:00:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s5Pr9-00F0s1-1X for pgsql-hackers@arkaria.postgresql.org; Fri, 10 May 2024 13:00:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s5Pr8-00F0rt-Md for pgsql-hackers@lists.postgresql.org; Fri, 10 May 2024 13:00:11 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s5Pr1-000Ll9-8b for pgsql-hackers@postgresql.org; Fri, 10 May 2024 13:00:10 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-522297f91easo279056e87.2 for ; Fri, 10 May 2024 06:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715346003; x=1715950803; darn=postgresql.org; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=HsPCPIBAQtcMpbH2R7d7ZYZ/pRZtjpsw/xcAR9utMuc=; b=VIOfK04WFQ36mDnImTX/wEhBLp5qzTMVA9h8NQBOSetCSkzhIZ6+tAPp2W9F1h6Ul9 0n/BVYcYVghNssfWjodk126Z03Zjw47UaQxNiOHBZzrOS/p+6YxqcFMup/JDv29Y2ZFb m6DRQn4GN0AASOjLKeeMAooOmMvz55QJF95WPxvR3p5afBSjTPL3vrw7fDAyDOsFvMD+ NNTQui6pYR+RH8z1BDLKbEpxEWLLgouMEes9FSGHkZyaqRjxd4AILWiRhBKT82CffMDM 00Up71JT1qVEQW3sB0UNA1fH/jmfiwBGLuIbyLy+5vjo2eaftiY5ATFLyOfMTcQpXJU4 2oqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715346003; x=1715950803; h=to:subject:from:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HsPCPIBAQtcMpbH2R7d7ZYZ/pRZtjpsw/xcAR9utMuc=; b=UhMQD83lIciUgD+2+6Ox36qsRRDCiVvXAdFTWtJ4FK4voiDzQ50KM/M9a6iOWBDGag rrZoyo6iGyhpWCwZIcHg+Zj5BExU3vocZUtqGVEsnBqy8TeR7zoCK5j2PDnmfp0IOntI mlWtCbC+LfI4O0nGgGbZWn02CCr8DOCMFv6a/lmUaJE3pNyC7mLdLR5NQB2THtqTGeCh LoyzY9vWTa3xnLEkrfY5FYvix0pbi4XADqDWR5ZHlEKeYX+PUmiyz0iCQHTx4ZZb2ej/ K7mEHptu/rXpdoZWuz4ZXoUN3XtTOA25nELoyr3K71n1aFQaCwISbivO6a3fQDouhtri 6RJA== X-Gm-Message-State: AOJu0YwzQcZrwVO6uKXUMv6NxQaTqmZOk0ylhKOuNMY2PbVabDCiGES3 /RJmEJbbW9GYVoCbFqFaBoqQaKMdZ0fHocQdjZe1wZB5DgWfbn9IRip+tg== X-Google-Smtp-Source: AGHT+IFxtBoR3eN7O8yI0aAkhSsRE0SG8YMW1SP38DPZqVLx2crbYhSahdjmXsRx4d7G39UMySl78g== X-Received: by 2002:a05:6512:3a8a:b0:51f:4c53:8e4c with SMTP id 2adb3069b0e04-5220fd785f3mr1851426e87.33.1715346002680; Fri, 10 May 2024 06:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.25.230]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-521f38d8c13sm673643e87.225.2024.05.10.06.00.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 May 2024 06:00:02 -0700 (PDT) Content-Type: multipart/mixed; boundary="------------waHpCIcKpWNPyWvgVo0tkUu0" Message-ID: <055bb33c-bccc-bc1d-c2f8-8598534448ac@gmail.com> Date: Fri, 10 May 2024 16:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Content-Language: en-US From: Alexander Lakhin Subject: WAL record CRC calculated incorrectly because of underlying buffer modification To: pgsql-hackers List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------waHpCIcKpWNPyWvgVo0tkUu0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello hackers, I've investigated a recent buildfarm failure: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=dodo&dt=2024-05-02%2006%3A40%3A36 where the test failed due to a CRC error: 2024-05-02 17:08:18.401 ACST [3406:7] LOG:  incorrect resource manager data checksum in record at 0/F14D7A60 (Chipmunk produced similar errors as well: https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=chipmunk&dt=2022-08-25%2019%3A40%3A11 https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=chipmunk&dt=2024-03-22%2003%3A20%3A39 https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=chipmunk&dt=2023-08-19%2006%3A43%3A20 ) and discovered that XLogRecordAssemble() calculates CRC over a buffer, that might be modified by another process. With the attached patch applied, the following test run: echo " autovacuum_naptime = 1 autovacuum_vacuum_threshold = 1 wal_consistency_checking = all " >/tmp/temp.config for ((i=1;i<=100;i++)); do echo "iteration $i"; TEMP_CONFIG=/tmp/temp.config TESTS="test_setup hash_index" make check-tests -s || break; done fails for me on iterations 7, 10, 17: ok 1         - test_setup                               2557 ms not ok 2     - hash_index                              24719 ms # (test process exited with exit code 2) postmaster.log contains: 2024-05-10 12:46:44.320 UTC checkpointer[1881151] LOG:  checkpoint starting: immediate force wait 2024-05-10 12:46:44.365 UTC checkpointer[1881151] LOG:  checkpoint complete: wrote 41 buffers (0.3%); 0 WAL file(s) added, 0 removed, 26 recycled; write=0.001 s, sync=0.001 s, total=0.046 s; sync files=0, longest=0.000 s, average=0.000 s; distance=439134 kB, estimate=527137 kB; lsn=0/3CE131F0, redo lsn=0/3CE13198 TRAP: failed Assert("memcmp(block1_ptr, block1_copy, block1_len) == 0"), File: "xloginsert.c", Line: 949, PID: 1881271 ExceptionalCondition at assert.c:52:13 XLogRecordAssemble at xloginsert.c:953:1 XLogInsert at xloginsert.c:520:9 hashbucketcleanup at hash.c:844:14 hashbulkdelete at hash.c:558:3 index_bulk_delete at indexam.c:760:1 vac_bulkdel_one_index at vacuum.c:2498:10 lazy_vacuum_one_index at vacuumlazy.c:2443:10 lazy_vacuum_all_indexes at vacuumlazy.c:2026:26 lazy_vacuum at vacuumlazy.c:1944:10 lazy_scan_heap at vacuumlazy.c:1050:3 heap_vacuum_rel at vacuumlazy.c:503:2 vacuum_rel at vacuum.c:2214:2 vacuum at vacuum.c:622:8 autovacuum_do_vac_analyze at autovacuum.c:3102:2 do_autovacuum at autovacuum.c:2425:23 AutoVacWorkerMain at autovacuum.c:1569:3 pgarch_die at pgarch.c:846:1 StartChildProcess at postmaster.c:3929:5 StartAutovacuumWorker at postmaster.c:3997:12 process_pm_pmsignal at postmaster.c:3809:3 ServerLoop at postmaster.c:1667:5 BackgroundWorkerInitializeConnection at postmaster.c:4156:1 main at main.c:184:3 /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7fc71a8d7e40] postgres: autovacuum worker regression(_start+0x25)[0x556a8631a5e5] 2024-05-10 12:46:45.038 UTC checkpointer[1881151] LOG:  checkpoint starting: immediate force wait 2024-05-10 12:46:45.965 UTC autovacuum worker[1881275] LOG: automatic analyze of table "regression.pg_catalog.pg_attribute"         avg read rate: 0.000 MB/s, avg write rate: 5.409 MB/s         buffer usage: 1094 hits, 0 misses, 27 dirtied         system usage: CPU: user: 0.01 s, system: 0.00 s, elapsed: 0.03 s 2024-05-10 12:46:46.892 UTC postmaster[1881150] LOG:  server process (PID 1881271) was terminated by signal 6: Aborted 2024-05-10 12:46:46.892 UTC postmaster[1881150] DETAIL:  Failed process was running: autovacuum: VACUUM ANALYZE public.hash_cleanup_heap (This can be reproduced with 027_stream_regress, of course, but it would take more time.) Best regards, Alexander --------------waHpCIcKpWNPyWvgVo0tkUu0 Content-Type: text/x-patch; charset=UTF-8; name="xloginsert-memchk.patch" Content-Disposition: attachment; filename="xloginsert-memchk.patch" Content-Transfer-Encoding: base64 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL2FjY2Vzcy90cmFuc2FtL3hsb2dpbnNlcnQuYyBi L3NyYy9iYWNrZW5kL2FjY2Vzcy90cmFuc2FtL3hsb2dpbnNlcnQuYwppbmRleCA5MDQ3NjAx NTM0Li5hZWI0NjJjMTM3IDEwMDY0NAotLS0gYS9zcmMvYmFja2VuZC9hY2Nlc3MvdHJhbnNh bS94bG9naW5zZXJ0LmMKKysrIGIvc3JjL2JhY2tlbmQvYWNjZXNzL3RyYW5zYW0veGxvZ2lu c2VydC5jCkBAIC05MDIsOCArOTAyLDIxIEBAIFhMb2dSZWNvcmRBc3NlbWJsZShSbWdySWQg cm1pZCwgdWludDggaW5mbywKIAkgKi8KIAlJTklUX0NSQzMyQyhyZGF0YV9jcmMpOwogCUNP TVBfQ1JDMzJDKHJkYXRhX2NyYywgaGRyX3NjcmF0Y2ggKyBTaXplT2ZYTG9nUmVjb3JkLCBo ZHJfcmR0LmxlbiAtIFNpemVPZlhMb2dSZWNvcmQpOworCitjaGFyIGJsb2NrMV9jb3B5W0JM Q0tTWl07CitjaGFyICpibG9jazFfcHRyID0gTlVMTDsKK2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