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 1r8AXP-008aUO-MD for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2023 02:42:55 +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 1r8AXO-008iJQ-8L for pgsql-hackers@arkaria.postgresql.org; Wed, 29 Nov 2023 02:42:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r8AXN-008iJI-V0 for pgsql-hackers@lists.postgresql.org; Wed, 29 Nov 2023 02:42:53 +0000 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r8AXL-007riG-89 for pgsql-hackers@postgresql.org; Wed, 29 Nov 2023 02:42:52 +0000 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-35c18e55633so20994145ab.2 for ; Tue, 28 Nov 2023 18:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701225770; x=1701830570; 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=8EEe7jxhxCuu87RBIlhHAl98sYbiChjyuzXVLVZuQYI=; b=gKPSvJ/Vf+Oq7CNAo9/qUYNh7/i8tZLwqlItOvBaGYpq6gazz0yj+3LRfbK5Ko42ye WlgsUuS7yuAb8YiYBjz5G7EVv8ZQKmSWRB15yNkI/L8vJT8TyGWFCq3VHEmC9zfsjZR+ DCsRgfFfDZHm7as4KGP/zrAj5cL9JPH5paxGuYPT6K75a9TyF8OcucEEW52NXWSdRRuN EgZRJW1xhQHxNEPDVmnfIv7zmnWxx9iYxCA7ghpkNNhcIdrI/pyelIqYVYHObeqY3o6k eCMKtH/U0TxppBb+zSA9e8M/uiveRLfeE8sLw1TYTE7i0yBx7YRrMUCdQ1+aIuVLg3Cf KKcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701225770; x=1701830570; 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=8EEe7jxhxCuu87RBIlhHAl98sYbiChjyuzXVLVZuQYI=; b=umPEQ9pbm+RIJySh5a/GO4yONrvgqUOmlAwzYSE9Sg2RTV4jwrV7Hz8IcqLV73ERk9 lu0BWHrr2UUXDu90YaX4L6qo5qlRa8G6erD9sk/DBmxBZuNMSZOQNz3XSUT5k8K0yFaP 4LJ4SgVh0RWs51mL/QaoNaj5Ro5pfSsxMwECg9b9IQkBOviuyh7ASmWPFOM3hhtqVcm2 wgLo0IIuSeLhDeFZ8z/GTey+7vO2tjGVaWiuEvOU8eC3tiWS+1Xq7s1ARxDGV9n9REph qmtVlq2zBN3y3wkAVk7ULqUltWS1BPKyghlYamExJfYaDrSeGi08LmbZjxd561u7v/FW Cu8Q== X-Gm-Message-State: AOJu0Yy3QinmCBo6suUIaBX0P0zRnvEwJKqAdYrZtLPU+RujhgfC+iz0 NIf8F2iAdqO6hpqmoX1UoUg= X-Google-Smtp-Source: AGHT+IHTkJN/8hZiXpCLSAdDjaGb6N2vCkloFooJfEVwY3CHjhhaEkftEE7Zz4pNqZSW8lGaIAK1nQ== X-Received: by 2002:a05:6e02:d50:b0:35c:d3f5:a42e with SMTP id h16-20020a056e020d5000b0035cd3f5a42emr9499588ilj.11.1701225770501; Tue, 28 Nov 2023 18:42:50 -0800 (PST) Received: from nathanxps13 ([162.195.168.172]) by smtp.gmail.com with ESMTPSA id c25-20020a5d9a99000000b0079263d9b6a8sm714118iom.11.2023.11.28.18.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 18:42:50 -0800 (PST) Date: Tue, 28 Nov 2023 20:42:47 -0600 From: Nathan Bossart To: Andres Freund Cc: David Geier , PostgreSQL-development Subject: Re: Fix assertion in autovacuum worker Message-ID: <20231129024247.GA479372@nathanxps13> References: <20231128220516.GA475168@nathanxps13> <20231129000349.pcfvrewvqk4he6i2@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231129000349.pcfvrewvqk4he6i2@awork3.anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Nov 28, 2023 at 04:03:49PM -0800, Andres Freund wrote: > On 2023-11-28 16:05:16 -0600, Nathan Bossart wrote: >> From a glance, it looks to me like the problem is that pgstat_shutdown_hook >> is registered as a before_shmem_exit callback, while ProcKill is registered >> as an on_shmem_exit callback. > > That's required, as pgstat_shutdown_hook() needs to acquire lwlocks, which you > can't after ProcKill(). It's also not unique to pgstat, several other > before_shmem_exit() callbacks acquire lwlocks (e.g. AtProcExit_Twophase(), > ParallelWorkerShutdown(), do_pg_abort_backup(), the first three uses of > before_shmem_exit when git grepping) - which makes sense, they are presumably > before_shmem_exit() because they need to manage shared state, which often > needs locks. > > In normal backends this is fine-ish, because ShutdownPostgres() is registered > very late (and thus is called early in the shutdown sequence), and the > AbortOutOfAnyTransaction() contained therein indirectly calls > LWLockReleaseAll() and very little happens outside of the transaction context. Right. Perhaps we could add a LWLockReleaseAll() to pgstat_shutdown_hook() instead of the autovacuum code, but I'm afraid that is still just a hack. >> I would expect your patch to fix this particular issue, but I'm wondering >> whether there's a bigger problem here. > > Yes, there is - our subsystem initialization, shutdown, error recovery > infrastructure is a mess. We've interwoven transaction handling far too > tightly with error handling, the order of subystem initialization is basically > random and differs between operating systems (due to EXEC_BACKEND) and "mode" > of execution (the order differs when using single user mode) and we've > distributed error recovery into ~10 places (all the sigsetjmp()s in backend > code, xact.c and and a few other places like WalSndErrorCleanup()). :( I do remember looking into uniting all the various sigsetjmp() calls before. That could be worth another try. The rest will probably require additional thought... -- Nathan Bossart Amazon Web Services: https://aws.amazon.com