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 1tL8Ym-00CwZD-6C for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Dec 2024 22:18:28 +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 1tL8Yj-009RYY-M0 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Dec 2024 22:18:26 +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 1tL8Yj-009RYP-B4 for pgsql-hackers@lists.postgresql.org; Tue, 10 Dec 2024 22:18:26 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tL8Yh-0029CM-CZ for pgsql-hackers@postgresql.org; Tue, 10 Dec 2024 22:18:25 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-3a7deec316aso21330695ab.1 for ; Tue, 10 Dec 2024 14:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733869101; x=1734473901; darn=postgresql.org; h=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=dUwRJ8ps64+naLKTVMg0PKjZGkR6Gt6HHgxGPFTuKbs=; b=hKyH3sUCZimsjh9Ifu8HvnlE2ZZlfMHMaZB2mQzBcYF0hZw4p2cMNidpv8ScLMV58a kYCUYuJ0Ukx0u6QSZq1RkAdaSq4IWj3Hshclw31ErA0UnnG3eJj2muKS9yC6Zvjm/oVX 7CWnQB29r648hSsBT4xdUGemRjGF4Jes6JmJyM48cRwoa8p29mM/BF2jFoLHILQtQZZS Dx99Ta6Fm6onCL9xjnan7N8uqLMJS/Ud/L18b8mqdEo6kKjAWEB5fkZ+tULualskf8h7 6Ltrm2Z6EY70PUhXZ4utiLz3TyrtzCvMrj1Zumt7KmGLfgy41j5MQfyUDoL56uQzHteI iMtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733869101; x=1734473901; h=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=dUwRJ8ps64+naLKTVMg0PKjZGkR6Gt6HHgxGPFTuKbs=; b=kof0IaQhlIpji6ojX549le8QALh38Dl9OChLz6XYU7JMsPCPk1zDvP667RJs6oUZ6l vYrKVAXhkkepBWkvycm8t23k0lVUWEt4tJtlX2ufhxsg5d/xVxmUqqQB73/xAkrX4P0j ekbo0nNfums2SYobFcSnGYSYRzh/cF3zMxq82mGrINesNUtXCFv0oBfqH7H1O4FlGM/M UMbQStNwjhF0bMkQaGIqOIqVsMfGRbFwX52q27VVrdcT0HAHbEJ+BDri/HlXCkpEBpkX oSZ5QdZ10JTABRKcZ8YgBpYN2OEMtXCa7KNVBzZxQSlnBtHCOtBZ4SZRYoYSrNjonsA5 LYVg== X-Gm-Message-State: AOJu0YzUN6b8QJfIB+fMdTcsEgHa/ef/9yqzbT7t9PfQQovvPC5YLAkH gYa8TEUuemMl0EgGohlsyFvPAZRTdNIxlLXMbdR6b+B3qNP+3y+F4JoG7g== X-Gm-Gg: ASbGnctjpzV8V2rybju/MXkb72YV/HCT9x3SdKtZEOfomvk4fwIb9pB9YIdXKY22HgV arhYdDNRm6xH00rIbZE3v7V38l1dkPCMu9SBIw5JbDusE/08Cvsa5z9RYWz1l9N0Z4wB01yCCPF SHY7UiJhtne9bYvJxXtr/UN779JtDx6KFnWwDLOBLgzT1gAelEWMDRfj/GWVjhqqpFhfdoNS+9r ulpxs38JLLC0jbcbfNeZMhyHafu/STsJiolADb07YIQgcl8j4N5TpULFlpzwtoCgvDgxPT5z8sB uIO/nwzyFcCNn3CPVJQUyeQihtf/HtfD2qQ6nwUsqaj4 X-Google-Smtp-Source: AGHT+IHD6Xm+Bs79L/KlnPA+QQJuraCRl9LUabsnvYkNkMVywsjra9ldzvkx3ZfiFgJWI24KMYlvUg== X-Received: by 2002:a05:6e02:1649:b0:3a7:d672:652d with SMTP id e9e14a558f8ab-3aa08f671dcmr4227775ab.16.1733869101491; Tue, 10 Dec 2024 14:18:21 -0800 (PST) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4e2beffad64sm1311043173.57.2024.12.10.14.18.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2024 14:18:21 -0800 (PST) Date: Tue, 10 Dec 2024 16:18:19 -0600 From: Nathan Bossart To: Noah Misch Cc: pgsql-hackers@postgresql.org Subject: Re: Fix early elog(FATAL) Message-ID: References: <20241208034614.45.nmisch@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241208034614.45.nmisch@google.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Dec 07, 2024 at 07:46:14PM -0800, Noah Misch wrote: > main() says: > > /* > * Fire up essential subsystems: error and memory management > * > * Code after this point is allowed to use elog/ereport, though > * localization of messages may not work right away, and messages won't go > * anywhere but stderr until GUC settings get loaded. > */ > MemoryContextInit(); > > However, appending elog(ERROR, "whoops") breaks like: > > $ initdb -D discard_me > FATAL: whoops > PANIC: proc_exit() called in child process > no data was returned by command ""/home/nm/sw/nopath/pghead/bin/postgres" -V" > child process was terminated by signal 6: Aborted > > So does the ereport(FATAL) in ClosePostmasterPorts(). The "called in child > process" check (added in commit 97550c0 of 2023-10) reads MyProcPid, which we > set later. 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 [0]. > 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. [0] https://postgr.es/m/20231122225945.3kgclsgz5lqmtnan%40awork3.anarazel.de -- nathan