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 1r86Cs-008D51-0v for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 22:05:26 +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 1r86Cp-007eBK-KH for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Nov 2023 22:05:23 +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 1r86Cp-007eBB-AJ for pgsql-hackers@lists.postgresql.org; Tue, 28 Nov 2023 22:05:23 +0000 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r86Cm-0093ol-5G for pgsql-hackers@postgresql.org; Tue, 28 Nov 2023 22:05:22 +0000 Received: by mail-io1-xd35.google.com with SMTP id ca18e2360f4ac-7b3b78e6729so74928439f.0 for ; Tue, 28 Nov 2023 14:05:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701209118; x=1701813918; 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=frmQ0oiMaE/oiKleTbmZQw4erfE8FussFpnUVJaws5k=; b=UNEYYUjMPJkMrnTKDzRgf9Nc0pNNk4ykWZUZdwMONJH4xQddKtKdiIaAWQLFwmaG7p QPNavgBFASnYkxhAgJiSdBE4nCu64jHm/0r7KEnG17DouXhJr9LulR7MJ5k6bHcPe1Fx mZUfvgqai66JM8X7U3NKVJNjcKvODrxjS9mfqf7tpxV8FvRrK2V+jfdW1pOjCun8bcjZ SpaJATEy/+qdIf8UuthsAF155b4Ij6U8qGHNXV82rmkrIq0JdC3Mzgys5VUbZG/ON8mr 1tIxviR81udzK4JD3GuzgHMueUtBacA7OQx7yXloN7+Oc+MGdwhzcnuUhVK2A1zRSjdD 5JTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701209118; x=1701813918; 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=frmQ0oiMaE/oiKleTbmZQw4erfE8FussFpnUVJaws5k=; b=i1buHiLzqIOz5zhojB08mrAu7UrprwVum+q49sTb3JedrYQemAk8EMlQR6WZtg5DXJ l3zaxXbA7O+DsXHkERjv0kObY5kRD9RIE4N6jDAPLSaovL/mrQUImM4SSsJz35DLFmkA crMd3tk77GhvptgERqaU1RaxZ/2zD7d6WQON4aeGAA1OYMf6hqUnVIPRa3b1gqUSPwdt xOymuLwdcs/Wbd+3wYAqHBI2JN7owdqlCIL310+N+8i3Zl4USx/CFIK48gOfL3kfNg0a xDMleMGXKtd+Gi1Or8KaVOFeei+2EUNyH8NJNeAjNNm6mfH+23zOUTWZ8Y/wiTRg1bow miDQ== X-Gm-Message-State: AOJu0Yxo9D9VDYbAiUOiVfn8Pqk6LclfPbm9np+KE3ntFtiGdGEg6zic YF71oIGfeni1OdKiigvrg60YEK60Tlk= X-Google-Smtp-Source: AGHT+IH+z0QeCSKXvv1sE3YysOm0caZpyrpg6izn2shy6XDOQ8MUGy6vsrrdAlQZA4LV7YRh9tVXWQ== X-Received: by 2002:a05:6602:2bf6:b0:7b3:9597:fab5 with SMTP id d22-20020a0566022bf600b007b39597fab5mr11222712ioy.8.1701209118188; Tue, 28 Nov 2023 14:05:18 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id l22-20020a5e8816000000b007b39250afc6sm617448ioj.9.2023.11.28.14.05.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Nov 2023 14:05:17 -0800 (PST) Date: Tue, 28 Nov 2023 16:05:16 -0600 From: Nathan Bossart To: David Geier Cc: PostgreSQL-development Subject: Re: Fix assertion in autovacuum worker Message-ID: <20231128220516.GA475168@nathanxps13> References: 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 Tue, Nov 28, 2023 at 07:00:16PM +0100, David Geier wrote: > PostgreSQL hit the following assertion during error cleanup, after being OOM > in dsa_allocate0(): > > void dshash_detach(dshash_table *hash_table) { > ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME(hash_table); > > called from pgstat_shutdown_hook(), called from shmem_exit(), called from > proc_exit(), called from the exception handler. Nice find. > AutoVacWorkerMain() pgstat_report_autovac() pgstat_get_entry_ref_locked() > pgstat_get_entry_ref() dshash_find_or_insert() resize() resize() locks all > partitions so the hash table can safely be resized. Then it calls > dsa_allocate0(). If dsa_allocate0() fails to allocate, it errors out. The > exception handler calls proc_exit() which normally calls LWLockReleaseAll() > via AbortTransaction() but only if there's an active transaction. However, > pgstat_report_autovac() runs before a transaction got started and hence > LWLockReleaseAll() doesn't run before pgstat_shutdown_hook() is called. 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. However, IIUC even moving them to the same list wouldn't be sufficient because the pg_stat_shutdown_hook is registered after ProcKill, and the code that calls the callbacks walks backwards through the list. I would expect your patch to fix this particular issue, but I'm wondering whether there's a bigger problem here. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com