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 1qO8tw-006vtN-6Q for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jul 2023 03:39:56 +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 1qO8tu-00EKMX-AB for pgsql-bugs@arkaria.postgresql.org; Tue, 25 Jul 2023 03:39:54 +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 1qO8tu-00EKMP-1t for pgsql-bugs@lists.postgresql.org; Tue, 25 Jul 2023 03:39:54 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qO8tr-000ASD-FT for pgsql-bugs@lists.postgresql.org; Tue, 25 Jul 2023 03:39:53 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id AC6A83200908; Mon, 24 Jul 2023 23:39:48 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 24 Jul 2023 23:39:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1690256388; x=1690342788; bh=4b 3ByIdGXTwWkJI9B7SI+VVuklrHqliE+cTJv1K0UZs=; b=UfBJshMf7QhGXYYpuq 3+4JLOJNMabuPk96WsZHrKE/2UhTG4rinXXJ2KxWLD0juwyN2CtQyLrAxhJh6ekl ixw34RtapVOhNxl3vI4qc1PBmuhRmaFlcSrAyouA6yESZBOCM4aJyIKen/52rIFy 4FBLVyCo+WHGtz+K5EyyxobX/xxVYr5k3bVEUJ9k4I4CtSSf3+1A7nxOpT888asF ajT6KZPTkF5MndqT6ug9NcpnnoeYW9EN8TxMBRUuW1Jm69Wm9/Z+DJat8NsEIwoX CSefujq5DQOVXf32VEWs0tLrKpBRWOYrhUYcbynL9wVYgenDAW1ffe014w+SS/b0 ji+Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1690256388; x=1690342788; bh=4b3ByIdGXTwWk JI9B7SI+VVuklrHqliE+cTJv1K0UZs=; b=bABp9J/gG9iqsHPlUYqlR7r5TJlwd zUrw3suN3Oz6hmscNbo/oKHyY75mWP3lUfx336P8KbkHIbYICCseYpix9GIqv8+7 I5cQ8o4X38MAcma92LW/V8OTFJ1uWmCI+jz4DSX2h/Hkn+pU7ajApj9HY5oEdCNy Cr2TG3tQzQutQh/Ii9NREQKVTpgLPZtzA53ZcqC62Nkc08SOg3Ekmwvuz7DtgNiE uOkZRsj4Q8ES1H/klnOd4LzHbqVdyrM5vmiZRifLfFrzgNa0lZIKBXXOFEcQxlbV DsGvmxVUyRrv3A0F/PO3GcSF97E26PKtCKT1I3ySYPdHp0uKGY/8mqucQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrheelgdejvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedvffefvefhteevffegieetfefhtddvffejvefhueetgeeludehteevudei tedtudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 24 Jul 2023 23:39:47 -0400 (EDT) Date: Mon, 24 Jul 2023 20:39:46 -0700 From: Andres Freund To: Masahiko Sawada Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18031: Segmentation fault after deadlock within VACUUM's parallel worker Message-ID: <20230725033946.mstudugbav7yghui@awork3.anarazel.de> References: <18031-ebe2d08cb405f6cc@postgresql.org> 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 Hi, Thanks for finding / debugging this issue! On 2023-07-21 17:01:11 +0900, Masahiko Sawada wrote: > I've reproduced the issue in my environment with the provided script. > The crashed process is not a parallel vacuum worker actually but a > parallel worker for rebuilding the index. The scenario seems that when > detecting a deadlock, the process removes itself from the wait queue > by RemoveFromWaitQueue() (called by CheckDeadLock()), and then > RemoveFromWaitQueue() is called again by LockErrorCleanup() while > aborting the transaction. With commit 5764f611e, in > RemoveFromWaitQueue() we remove the process from the wait queue using > dclist_delete_from(): > > /* Remove proc from lock's wait queue */ > dclist_delete_from(&waitLock->waitProcs, &proc->links); > : > /* Clean up the proc's own state, and pass it the ok/fail signal */ > proc->waitLock = NULL; > proc->waitProcLock = NULL; > proc->waitStatus = PROC_WAIT_STATUS_ERROR; > > However, since dclist_delete_from() doesn't clear proc->links, in > LockErrorCleanup(), dlist_node_is_detached() still returns false: > > if (!dlist_node_is_detached(&MyProc->links)) > { > /* We could not have been granted the lock yet */ > RemoveFromWaitQueue(MyProc, lockAwaited->hashcode); > } Indeed :( > leading to calling RemoveFromWaitQueue() again. I think we should use > dclist_delete_from_thoroughly() instead. With the attached patch, the > issue doesn't happen in my environment. Yep. Do you want to push that fix, or should I? > Another thing I noticed is that the Assert(waitLock) in > RemoveFromWaitQueue() is useless actually, since we access *waitLock > before that: > > I think we should fix it as well. This fix is also included in the > attached patch. Don't really have an opinion on that. It's been this way for longer, afaict. Greetings, Andres Freund