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 1mCOTl-0004bM-Mg for pgsql-committers@arkaria.postgresql.org; Sat, 07 Aug 2021 15:43:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mCOTk-0001t0-K0 for pgsql-committers@arkaria.postgresql.org; Sat, 07 Aug 2021 15:43:16 +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 1mCOTk-0001rv-Dy for pgsql-committers@lists.postgresql.org; Sat, 07 Aug 2021 15:43:16 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mCOTf-00085Y-Og for pgsql-committers@lists.postgresql.org; Sat, 07 Aug 2021 15:43:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 177Fh7q52675113; Sat, 7 Aug 2021 11:43:07 -0400 From: Tom Lane To: Andres Freund cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: pgstat: Bring up pgstat in BaseInit() to fix uninitialized use o In-reply-to: <20210807051149.x2j3n64ejcu23hm4@alap3.anarazel.de> References: <2638683.1628304247@sss.pgh.pa.us> <20210807030652.qf5wsbhxk7dpsmtn@alap3.anarazel.de> <2640064.1628306008@sss.pgh.pa.us> <2640490.1628306556@sss.pgh.pa.us> <20210807044952.orwuf7hua2wytx4g@alap3.anarazel.de> <20210807051149.x2j3n64ejcu23hm4@alap3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Fri, 06 Aug 2021 22:11:49 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2675111.1628350987.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 07 Aug 2021 11:43:07 -0400 Message-ID: <2675112.1628350987@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2021-08-06 21:49:52 -0700, Andres Freund wrote: >> Not yet really sure what the best way to deal with this is. Presumably = this >> issue would be fixed if AtProcExit_Files()/CleanupTempFiles() were sche= duled >> via before_shmem_exit(). And perhaps it's not too off to schedule >> CleanupTempFiles() there - but it doesn't quite seem entirely right eit= her. > Huh. I just noticed that AtProcExit_Files() is not even scheduled via > on_shmem_exit() but on_proc_exit(). That means that even before fb2c502= 8e63 > we sent pgstat messages *well* after pgstat_shutdown_hook() already > ran. Crufty. > Just hacking in an earlier CleanupTempFiles() does "fix" the OSX issue: > https://cirrus-ci.com/task/5941265494704128?logs=3Dmacos_basebackup#L4 So if I have the lay of the land correctly: 1. Somebody decided it'd be a great idea for temp file cleanup to send stats collector messages. 2. Temp file cleanup happens after shmem disconnection. 3. This accidentally worked, up to now, because stats transmission happens via a separate socket not shared memory. 4. We can't keep both #1 and #2 if we'd like to switch to shmem-based stats collection. Intuitively it seems like temp file management should be a low-level, backend-local function and therefore should be okay to run after shmem disconnection. I do not have a warm feeling about reversing that module layering --- what's to stop someone from breaking things by trying to use a temp file in their on_proc_exit or on_shmem_exit hook? Maybe what needs to go overboard is point 1. More generally, this points up the fact that we don't have a well-defined module hierarchy that would help us understand what code can safely do whi= ch. I'm not volunteering to design that, but maybe it needs to happen soon. regards, tom lane