Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNhdx-0006XM-VY for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Feb 2023 22:01:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNhdw-0004it-Q3 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Feb 2023 22:01:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNhdw-0004iQ-Db for pgsql-hackers@lists.postgresql.org; Thu, 02 Feb 2023 22:01:20 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pNhdt-0003UD-UY for pgsql-hackers@lists.postgresql.org; Thu, 02 Feb 2023 22:01:19 +0000 Received: by mail-pj1-x102f.google.com with SMTP id c10-20020a17090a1d0a00b0022e63a94799so6991922pjd.2 for ; Thu, 02 Feb 2023 14:01:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=47uq9nefyDlsdkahqFdj5PT2Xj+QYLDTPmG2iBRsKAE=; b=C7czsPCheXVqA7JEZqr9h/XbjGE86rhsIrqUFKV6PNEHQLyUh42l5smcITnGQbAfcL /83dAOjnI76adgJsTX9ztCAu3xvhv+hF+HWYJGlMdnA/xNKSwnGPOQ/AFXEBFtrfn+od 1nNH0gN4XD8tW6C2KHwZk0rFLTRGnz1S34DCbrCSYja93QWt/jkWmI33YEy8wLl5Eufx oEdvcW6DRs2ATPCV+zF5+1oGJUTizI76gVsMzJ79tPW+CD/KTPzd7oWSfO17Z24xsOoE HBXsU2AamPFlBBMqhorNeecV9m9qtIx+MotF6nSfqYYwcKrZWXG6Ug9JHBgahhElVzQr Mbmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=47uq9nefyDlsdkahqFdj5PT2Xj+QYLDTPmG2iBRsKAE=; b=eAcTNXg8h5Ded2Wivx00fKlmuBSp3dwq5JF8POD3qP0bKYG0bgomZHOiLf9LSzSjfz ZLeJDodAjAI/Ow53XyM30b/jzx5eIf2Q2as7FOuSViQLX5dJ3FXXGstmIWha/oEGkqr3 +ONUFqYJX3mFDQ7UjQE689rWe3yrcvcV73ePpnIWjpJc+A+u5fLDChFLWg8N2snz5nIL LMqkzlmUPQaTFQDlxWZDkNmg0EhKNGC3QsGLCk2Y3IH9n0bE0hKLkH8Nchq/CvC/CZAY q1dZlJMSNVa82Td1SgA1g5rKu4bmAjg1cai8Ov0DycK+EB6RaMBPHfFTcCkQ1h1+tuEb A/uQ== X-Gm-Message-State: AO0yUKUkyoPGMsaWSPB9mWoo3yemsmau66DQAwGo1u/Zo4wfnc7Ri+Un Ocjcjl5wu3chO+/dh7ZyI+U= X-Google-Smtp-Source: AK7set+X1tUyqtythfANv4JHD5w6h6Yuc8DBqqkZjsoYqy/Dfkl8ey8ux5+LIMnG9TlIItP3knHr6w== X-Received: by 2002:a17:902:f54c:b0:198:9988:5e2f with SMTP id h12-20020a170902f54c00b0019899885e2fmr9122196plf.26.1675375276375; Thu, 02 Feb 2023 14:01:16 -0800 (PST) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id a7-20020a170902710700b00196048cc113sm150585pll.126.2023.02.02.14.01.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Feb 2023 14:01:15 -0800 (PST) Date: Thu, 2 Feb 2023 14:01:13 -0800 From: Nathan Bossart To: Robert Haas Cc: Michael Paquier , Tom Lane , Andres Freund , Thomas Munro , Fujii Masao , Postgres hackers Subject: Re: Weird failure with latches in curculio on v15 Message-ID: <20230202220113.GA3945808@nathanxps13> References: <20230201105514.rsjl4bnhb65giyvo@alap3.anarazel.de> <1369666.1675264346@sss.pgh.pa.us> <20230201165801.33ydbxvjdbomjqa7@alap3.anarazel.de> <20230201175806.GA3199959@nathanxps13> <20230201223555.GA3721373@nathanxps13> <1449633.1675305284@sss.pgh.pa.us> <20230202200957.GA3944544@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Feb 02, 2023 at 04:14:54PM -0500, Robert Haas wrote: > + /* > + * When exitOnSigterm is set and we are in the startup process, use the > + * special wrapper for system() that enables exiting immediately upon > + * receiving SIGTERM. This ensures we can break out of system() if > + * required. > + */ > > This comment, for me, raises more questions than it answers. Why do we > only do this in the startup process? Currently, this functionality only exists in the startup process because it is only used for restore_command. More below... > Also, and this part is not the fault of this patch but a defect of the > pre-existing comments, under what circumstances do we not want to exit > when we get a SIGTERM? It's standard behavior for PostgreSQL backends > to exit when they receive SIGTERM, so the question isn't why we > sometimes exit immediately but why we ever don't. The existing code > calls ExecuteRecoveryCommand with exitOnSigterm true in some cases and > false in other cases, and AFAICS there are zero words of comments > explaining the reasoning. I've been digging into the history here. This e-mail seems to have the most context [0]. IIUC this was intended to prevent "fast" shutdowns from escalating to "immediate" shutdowns because the restore command died unexpectedly. This doesn't apply to archive_cleanup_command because we don't FATAL if it dies unexpectedly. It seems like this idea should apply to recovery_end_command, too, but AFAICT it doesn't use the same approach. My guess is that this hasn't come up because it's less likely that both 1) recovery_end_command is used and 2) someone initiates shutdown while it is running. BTW the relevant commits are cdd46c7 (added SIGTERM handling for restore_command), 9e403c2 (added recovery_end_command), and c21ac0b (added what is today called archive_cleanup_command). > + if (exitOnSigterm && MyBackendType == B_STARTUP) > + rc = RunInterruptibleShellCommand(command); > + else > + rc = system(command); > > And this looks like pure magic. I'm all in favor of not relying on > system(), but using it under some opaque set of conditions and > otherwise doing something else is not the way. At the very least this > needs to be explained a whole lot better. If we applied this exit-on-SIGTERM behavior to recovery_end_command, I think we could combine failOnSignal and exitOnSigterm into one flag, and then it might be a little easier to explain what is going on. In any case, I agree that this deserves a lengthy explanation, which I'll continue to work on. [0] https://postgr.es/m/499047FE.9090407%40enterprisedb.com -- Nathan Bossart Amazon Web Services: https://aws.amazon.com