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 1rNg5C-00EWNi-9Q for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 21:25: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 1rNg5A-007iS0-DC for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jan 2024 21:25:52 +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 1rNg5A-007iRr-0s for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 21:25:52 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNg56-000u3f-IS for pgsql-hackers@lists.postgresql.org; Wed, 10 Jan 2024 21:25:50 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4T9LSQ1y7Mz49Pv3; Wed, 10 Jan 2024 23:25:42 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1704921942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Lqrf3FaEVUwXIQveBh+JefoOkdgT9Nny7SqyH40Ogo=; b=TRNbid6xpACnmwdYzg8eitu3OgtQnKSrz/K20e5vYiDiTV0wg6vq3RnhTJEv20Fdvfb68D Z2GHPl0ZG7rZvVCSQse4yqNDF2meE8oKz2lGwK74wrT78onbGkveIsqOw5qeO2YlDiXUKU eGjHQh2MUk3MioXaIjYUHxvRpy954NxUo7NKWAzYXsqZBlnooTpJHXbeMOxMv2rgV5Zlkg AC016b3ys3eGwKRDNU8YCh8Yw73eImhLNaOE5QCanwvYsbsy+lbJKy+vob87MzFjr784me 1h7dhmafpU2C7a1O1FIdtqNKnlc5+2iy1ajZJKi9kaWW8Xb3UEAMYqL+nO2Y2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1704921942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Lqrf3FaEVUwXIQveBh+JefoOkdgT9Nny7SqyH40Ogo=; b=AhOPMZ92nhUx8++bsxukyLf3AnNifNR6vQIFYtV6ERDF/JPli/jTf7A3F6Sld3elTfQI56 BJT90IhI3RY5KmSFwc4M4wlCWicyGxW70MepVGr1zpFJcBcNONFl4L/Ipa3kF8Aiw8G3Ym g/mR4rYdEfbMPbk8/cTKxfTMKjOperWqTYh64k3hxiSQCd5Sjyrv02rrAJBsAbgmn3uWJb foUJKGhV9e8mria6SCnPCfc7G35nJHodYGFDXHrdR+lERDdwabYG9dfo2yDgiCG6/8pbJo CbNjNyGTpyeFfNd65407VRCwFq2/7x/80qrxm7hWfg/hyzx2DdvDVsTBkW4kJA== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1704921942; a=rsa-sha256; cv=none; b=neEG0M60cdo64qVLxrb9Dw7DRD9J2LCfOnitxRMbS4Rxyh1CoZDlcbOCh5d1TAAaSQ9nbh /Y9pray5qgCOXL1ksadZqNrTvXdqE3NMbWqbYobco8LCQEBekKTyymPxLdAi+sxiacGYlN fKueT+rOLaqywqcT31nJQ03WbWYlCSmzBco4B0LMcjU7IACvLJMg+vUK2MS0BclHPry0Lb kPDHh0LPenhboMYNTUQQOGd6elRkb01wRmuGs7vYT+cRCuCHQSYizIQQQCaINbDuISg2Or cRisxPXO3qnWL62gjKwpf9304G1FxabjvbNlaA/PDBZcuP1aohUyNQKEoFXmQQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Wed, 10 Jan 2024 23:25:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Stack overflow issue Content-Language: en-US To: Robert Haas Cc: Egor Chindyaskin , Sascha Kuhl , pgsql-hackers@lists.postgresql.org References: <1661334672.728714027@f473.i.mail.ru> <485cf2a2-d504-fb5f-6751-1085ccf614ec@mail.ru> <4530546a-3216-eaa9-4c92-92d33290a211@mail.ru> <6b48c746-9704-46dc-b9be-01fe4137c824@iki.fi> From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 05/01/2024 19:23, Robert Haas wrote: > On Fri, Nov 24, 2023 at 10:47 AM Heikki Linnakangas wrote: >> What do you think? > > At least for 0001 and 0002, I think we should just add the stack depth checks. > > With regard to 0001, CommitTransactionCommand() and friends are hard > enough to understand as it is; they need "goto" like I need an extra > hole in my head. > > With regard to 0002, this function isn't sufficiently important to > justify adding special-case code for an extremely rare event. We > should just handle it the way we do in general. > > I agree that in the memory-context case it might be worth expending > some more code to be more clever. But I probably wouldn't do that for > MemoryContextStats(); check_stack_depth() seems fine for that one. > > In general, I think we should try to keep the number of places that > handle stack overflow in "special" ways as small as possible. The problem with CommitTransactionCommand (or rather AbortCurrentTransaction() which has the same problem) and ShowTransactionStateRec is that they get called in a state where aborting can lead to a panic. If you add a "check_stack_depth()" to them and try to reproducer scripts that Egor posted, you still get a panic. I'm not sure if MemoryContextStats() could safely elog(ERROR). But at least it would mask the "out of memory" that caused the stats to be printed in the first place. -- Heikki Linnakangas Neon (https://neon.tech)