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 1qVN9h-0000eS-JK for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Aug 2023 02:18:06 +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 1qVN0q-00CUc8-5Y for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Aug 2023 02:08:56 +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 1qVN0o-00CUc0-O6 for pgsql-bugs@lists.postgresql.org; Mon, 14 Aug 2023 02:08:56 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qVN0m-0000YJ-KN for pgsql-bugs@lists.postgresql.org; Mon, 14 Aug 2023 02:08:54 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 280C0320014C; Sun, 13 Aug 2023 22:08:48 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 13 Aug 2023 22:08:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1691978927; x=1692065327; bh=2N O8o1z3Co09ihheN9JjSQr9UkvhZqxGmVlHHt5u4Wo=; b=E4VhICvON4iXTaUpNN SwCRRPyCLLpVpND+FNSZHPmZm1giqT6XcFVIOdNu09Mas9sNq6An70W+3A1zNfLq GP4mJeQK980BQdl6QWkamtq4xZXYGwx0WBfNGlIfJhaLIhM+2w9VsmzH+qX8xunI oY9hm7b2hWKgfmtxKQhIXwUrNAj2FDaVM/E9Sr1/k1dHIBSNv9gtEUjAJ8SE9kR5 rEEU30Lgo4D7x1Bd7ovs9wO1ooHPvmwAkZX4RrnfbK40TZZt3TTYTUJdDoY/dj7W JV80hpUWMdOaotJ24JlrfnOPmx76EJk+uiXEuVGMDnJa/JcjhfHuqa0xa26BsgnV iFBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1691978927; x=1692065327; bh=2NO8o1z3Co09i hheN9JjSQr9UkvhZqxGmVlHHt5u4Wo=; b=OuZHELqgu2rTcpezoz7za/coOIkhb arVpyAOEizZt42xCyJUc+xxSX1vzEY7ApvbIjBVQRbCYJlsKEhiiyn3EtO8FvNj9 9FL2HxHZ9D+aSc3c5rjbnWllbGZY0FcQ1nY5w5/XAt3NtN9+6aygr9D7PPRg9zQ0 0tz+7xP44xCT0v3P725FccLaRb/aFGJL/iS2WShvG8F5+m7h4GpFTCtaFmYytglB QUhNDh6YKm3fkAigUm57YcXQKdLWldNEBdwa0Y18IfqsQrz+eZ/FxbdypykZK5si 077tb7KXgB43gF1aBX8GMy3WKxgBLC2SzOCh+HPHXxQKnkhf+7FH4Na/A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddtfedgheeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tdejnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeu ieeuieevueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 13 Aug 2023 22:08:45 -0400 (EDT) Date: Mon, 14 Aug 2023 11:08:40 +0900 From: Michael Paquier To: Noah Misch Cc: Thomas Munro , Tom Lane , 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: References: <20230811025808.GA2261232@rfd.leadboat.com> <20230811140008.GB2261449@rfd.leadboat.com> <351991.1691800320@sss.pgh.pa.us> <20230812211327.GB2326466@rfd.leadboat.com> <20230813033034.GD2326466@rfd.leadboat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="lw8rhO9VwtDkHi0Q" Content-Disposition: inline In-Reply-To: <20230813033034.GD2326466@rfd.leadboat.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --lw8rhO9VwtDkHi0Q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Aug 12, 2023 at 08:30:34PM -0700, Noah Misch wrote: > On Sun, Aug 13, 2023 at 03:12:34PM +1200, Thomas Munro wrote: >> On Sun, Aug 13, 2023 at 9:13=E2=80=AFAM Noah Misch w= rote: >>> 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 o= ne 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 oversi= zed >>> record. A side benefit would be avoiding useless large allocations (1GB >>> backend, 4GB frontend) as discussed upthread. May as well do the xl_rm= id and >>> xl_prev checks in all branches, to avoid needless XLogRecordMaxSize-1 >>> allocations. Thoughts? For invalid-length records in v16+, since ever= y 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? +1 for relying on xlp_rem_len for that. > Hmm, I think that is right. A coincidental match of the 32-bit CRC is mo= re > probable than having all those fields appear valid by coincidence, especi= ally > xlp_pageaddr. Hmm. [.. thinks ..] It seems to me that we should try to also finish the header validation before attempting XLogReadRecordAlloc() on the total_len as well? It looks like the end result would be to move the first ReadPageInternal done for the header with all its cross-page checks before XLogReadRecordAlloc(). That should remove the need of having gotheader from v1. -- Michael --lw8rhO9VwtDkHi0Q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmTZjKgACgkQnvQgOdby QH0WHQ//db7EdfPGAARtpHUJgHI18sMAwancXwolv328/JDjR1vdozl2XCv/phs/ R0w255JTYTIhiMuBc1iipoNhpaVOCbIPYS7aog/YUljbYXgWyBBJfSAIySUHU3vx 1N/p+Fu5U9dFKarhIJj8JRaRSDWbsvU3/+t1G6JcueYHfZ0/kP/ysnm3eBv0jY6n On+tfxgjet49fKi4tcN5oGmwjpnEGNqiHwbwxeT1FYN8Jtvdh/lJ56j4GdIyfRBi dfGO0vgAR/3OAw/MkpkxmhlAsFZHIH++YY9MB+SjYuCIyw/QlQR8q70EywRBuLkO 6MhH9J4dUujnbVxWh07U9pn8p5tmlYyFaJvE2Qfw8sIsssF4vwCbY4kMlqZ7CgZd OGvOOy53+XWEQhUP5ZtMWSbsGYt+4zm5j18khOu874tsUFry1TV7rcnlc7lXBS/A N9K+GtaJXMUn5S9lg1TezJpuLmR0xCt8XHVLKCuOYPG4KsO0yUDT4iiAdB3XBBT7 3coxbjMZGIG3LhLbYjFIo1vIysjIkywoFPTVzqongDoTaRL08kuPpMR4agO4kDQo scLE7nQDJsfkqSAhb8z0w9SVDhFCKTINYQVwXjw68fkYsMy+E1KnmTNTcQiUSRMB kgYLnrcp7SXSNJN7YPVlz7/nyINvyQmD4iiUm2wgKfFUy1zeJXU= =avBt -----END PGP SIGNATURE----- --lw8rhO9VwtDkHi0Q--