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 1qV1oQ-00G7o5-UX for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Aug 2023 03:30:43 +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 1qV1oP-005UMq-8L for pgsql-bugs@arkaria.postgresql.org; Sun, 13 Aug 2023 03:30:41 +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.94.2) (envelope-from ) id 1qV1oO-005UMV-W3 for pgsql-bugs@lists.postgresql.org; Sun, 13 Aug 2023 03:30:41 +0000 Received: from mail-yw1-x112c.google.com ([2607:f8b0:4864:20::112c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qV1oM-0024e6-4C for pgsql-bugs@lists.postgresql.org; Sun, 13 Aug 2023 03:30:39 +0000 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-589bcdaa8a4so23371637b3.3 for ; Sat, 12 Aug 2023 20:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1691897437; x=1692502237; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=iukwNiQZZxi9DWKRqV8Ye+F5Q94o9O82TelJw6ttjtc=; b=X8ZJaW3R+rc5QheY4Gi72iZ5cmswujB1gSAZhM9CFDFUrDT2ccxl2ANHdGi/93PImw zQaw/3pRZIMJPLzJIpuKFu+uWDOC4JJbhIb7TofB0pq/ej/2SZvl7U1wz3b8r4gIgFfF T/Xzh11ZzSOGu6C6cdkVZkW6cGzdTlJKLpXpY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691897437; x=1692502237; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iukwNiQZZxi9DWKRqV8Ye+F5Q94o9O82TelJw6ttjtc=; b=egtTmHGvYCE5qs1Whs5bZHiOQp7vvDnTyWnGEHsDAJRymp7rF7He1ZnMhcy7KCuqEq or36C0fJOoZDYblUr3RwrjkYPmSO0Kmx41T2z78X+EDLPfHf/Ge74VD/hreDhS+qHyHI vGa9KHRKtruLK9MLMueJA5hXcv/USU3GqhwYImEDPqgqcbc8/Ax3FBFVBSS9D+mdU9cG boOk4qdo0Nzx5HW9s8suP6z5hirRL6d0SvtyvzDPaDPZPkK4Gd6sfGgRbPX1V+jJ0DU6 i30KXN3l/HLBYteCEE67frAJ/3R6ySDK9GWaJFr7fJctDqPA4IPYrkzsUFjNtKzbrLrD k/zg== X-Gm-Message-State: AOJu0YwdC5W9djsic/KMnL9MbJHhqwThmX9q7b7/zIyhY1dwFstQ3bEm V7HlqfHevi/siiOU4Qo3Rz2qHA== X-Google-Smtp-Source: AGHT+IG1mxtOkTCYbPlkCuWFG22WBCJnBasW0SAffiP8QAH8pXIbCnxF4ExsWSG9j8wbAW6rctNBCg== X-Received: by 2002:a0d:ea02:0:b0:586:a2f9:648e with SMTP id t2-20020a0dea02000000b00586a2f9648emr7292240ywe.4.1691897437387; Sat, 12 Aug 2023 20:30:37 -0700 (PDT) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id p81-20020a815b54000000b00565271801b6sm1987752ywb.59.2023.08.12.20.30.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Aug 2023 20:30:36 -0700 (PDT) Date: Sat, 12 Aug 2023 20:30:34 -0700 From: Noah Misch To: Thomas Munro Cc: Tom Lane , Michael Paquier , Kyotaro Horiguchi , exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17928: Standby fails to decode WAL on termination of primary Message-ID: <20230813033034.GD2326466@rfd.leadboat.com> References: <20230717004905.GE3826297@rfd.leadboat.com> <20230811025808.GA2261232@rfd.leadboat.com> <20230811140008.GB2261449@rfd.leadboat.com> <351991.1691800320@sss.pgh.pa.us> <20230812211327.GB2326466@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Aug 13, 2023 at 03:12:34PM +1200, Thomas Munro wrote: > On Sun, Aug 13, 2023 at 9:13 AM Noah Misch wrote: > > Any user could call pg_logical_emit_message() to silently terminate the WAL > > stream, which is far worse than the original bug. So far, I'm seeing one way > > to clearly fix $SUBJECT without that harm. When a record header spans a page > > boundary, read the next page to reassemble the header. If > > !ValidXLogRecordHeader() (invalid xl_rmid or xl_prev), treat as end of WAL. > > Otherwise, read the whole record in chunks, calculating CRC. If CRC is > > invalid, treat as end of WAL. Otherwise, ereport(FATAL) for the oversized > > record. A side benefit would be avoiding useless large allocations (1GB > > backend, 4GB frontend) as discussed upthread. May as well do the xl_rmid and > > xl_prev checks in all branches, to avoid needless XLogRecordMaxSize-1 > > allocations. Thoughts? For invalid-length records in v16+, since every such > > record is end-of-wal or corruption, those versions could skip the CRC. > > That sounds quite strong. But... why couldn't the existing > xlp_rem_len cross-check protect us from this failure mode? If we > could defer the allocation until after that check (and the usual > ValidXLogRecordHeader() check), I think we'd know that we're really > looking at a size that was actually written in both pages (which must > also have survived xlp_pageaddr check), no? Hmm, I think that is right. A coincidental match of the 32-bit CRC is more probable than having all those fields appear valid by coincidence, especially xlp_pageaddr.