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 1tLZy5-00Ffqj-0B for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Dec 2024 03:34:25 +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 1tLZy1-006C8D-HV for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Dec 2024 03:34:22 +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 1tLZy0-006C83-V1 for pgsql-hackers@lists.postgresql.org; Thu, 12 Dec 2024 03:34:22 +0000 Received: from mail-oa1-x2f.google.com ([2001:4860:4864:20::2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tLZxz-002OJM-8R for pgsql-hackers@postgresql.org; Thu, 12 Dec 2024 03:34:21 +0000 Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-29e5c0c46c3so75615fac.3 for ; Wed, 11 Dec 2024 19:34:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1733974458; x=1734579258; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=5FEqT5f5BVAOJsp+1MQRv7/LMmTayY4TwJeCFU6Tflo=; b=NeKePo7cT3fpPLOIFDEde1FPvHpP/BBsfizUmhiWZTmt1uTPbiRkyVKuJGVPucM6bg RSrJcBmCu7YalmlgUISOkGcdvyo+R9M1oE4nM50fpUg+dVf4XPfPBYpkHF/9ISQlt6uw Pc8u71CYf3pViRQqQV9zbrdfTxm0S+LPIyA6A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733974458; x=1734579258; h=user-agent:in-reply-to: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=5FEqT5f5BVAOJsp+1MQRv7/LMmTayY4TwJeCFU6Tflo=; b=EBx8EL3GXH34m2pVcvXVxMoklPj0gbhNDRKtSguel23mJPMt5Yby97ASZwhClpaMIT yupNyrvNAkB1J3/T7nVVVqyOYTLCRn1A/zpsgN4BhVrAbcl3pgv6022t8hvrlKHX+Q3p CQqpOoz05RIg/U8LocNx6XY9fmjJXk+AZiE6Ik8S17WmF8hImXphgk33T2bdU6fN5Xqj FE5WyiIY38Xbvx3h8k5JuHJ+s+PV3ilwsMFSp1rD78T9dSww4xWGp012r2ryi+PaxX1G rhPeA6FX5Mf//Nc1Sa+LglcTW2mXhgCe7FVRueVVaIMIFYmmeghEd6e2pqFpeU1wFKud 6Xxg== X-Gm-Message-State: AOJu0Yz7ysUMdklpYxtIqK96O4i62CgB4EID6SRGBp56yCXPVR10MO94 o7FZBHoK4oSJfP8x/BF4YfIty2mkybk7mcCy7VelRuN9AkBPmU3NgTZq81IyAo4KELO58zs2y+A = X-Gm-Gg: ASbGncsPE4vj+DuNvdJCcqU9coLZ02oEcgbo+9Uemo4LDLMd1Y9ZqRQbAjjuk0KvyjE qSgUiAHXpjmqOmEs6+X+9aA40huTr2Yi8puaORpsYm9ikbtdVRZpf6GtfbPxPguBcDt9vUEqalW EmInMMEUFmI1eYtppOjCj0ePYyJh03XSsBBnJs7gD8jDDvs3KHrYtxZUY+7rIaiu4sJV2Hwkb6K T8B+KvWtD7wMgrytkemLyinvgr+QmFD4gfrnbWJ/guIBTMWxw0= X-Google-Smtp-Source: AGHT+IFQM/pHSCCKgSdaIOFh/wPXA0kkTeRlUs8+mtWm3Xp84tax4srTYUxe+GSBT3OHhxbmuUUrTA== X-Received: by 2002:a05:6870:249f:b0:27c:a414:b907 with SMTP id 586e51a60fabf-2a38269e4aamr1369140fac.33.1733974458145; Wed, 11 Dec 2024 19:34:18 -0800 (PST) Received: from google.com ([2600:1702:a20:5750::48]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-29f7d768902sm3568534fac.51.2024.12.11.19.34.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2024 19:34:17 -0800 (PST) Date: Wed, 11 Dec 2024 19:34:14 -0800 From: Noah Misch To: Nathan Bossart Cc: pgsql-hackers@postgresql.org Subject: Re: Fix early elog(FATAL) Message-ID: <20241212033414.e0.nmisch@google.com> References: <20241208034614.45.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Dec 10, 2024 at 04:18:19PM -0600, Nathan Bossart wrote: > On Sat, Dec 07, 2024 at 07:46:14PM -0800, Noah Misch wrote: > > Three ways to fix this: > > I noticed that you committed a fix for this. Sorry for not responding > earlier. > > > 1. Call InitProcessGlobals() earlier. This could also reduce the total call > > sites from 3 to 2 (main() and post-fork). > > > > 2. Move MyProcPid init out of InitProcessGlobals(), to main() and post-fork. > > This has less to go wrong in back branches. While probably irrelevant, > > this avoids calling pg_prng_strong_seed() in processes that will exit after > > help() or GucInfoMain(). > > > > 3. Revert 97550c0, as commit 3b00fdb anticipated. > > I did partially revert 97550c0 in commit 8fd0498, but we decided to leave > some of the checks Got it. Old branches couldn't merely do (3), anyway, since 3b00fdb is v17+. I missed that while writing the list. > > I don't think the choice matters much, so here is (2). > > FWIW I'd probably vote for option 1. That keeps the initialization of the > globals together, reduces the call sites, and fixes the bug. I'd worry a > little about moving the MyProcPid assignments out of that function without > adding a bunch of commentary to explain why. Can you say more about that? A comment about MyProcPid could say "fork() is the one thing that changes the getpid() return value". To me, the things InitProcessGlobals() sets are all different. MyProcPid can be set without elog(ERROR) and gets invalidated at fork(). The others reasonably could elog(ERROR). (They currently don't.) The random state could have a different lifecycle. If we had a builtin pooler that reused processes, we'd reinitialize random state at each process reuse, not at each fork(). So I see the grouping of (MyProcPid, MyStartTimestamp, random seed) as mostly an accident of history. Thanks, nm