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.96) (envelope-from ) id 1wttX4-000LAd-0h for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Aug 2026 20:57:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wttX2-004878-0H for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Aug 2026 20:57:09 +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.96) (envelope-from ) id 1wttX1-004870-2a for pgsql-hackers@lists.postgresql.org; Tue, 11 Aug 2026 20:57:08 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wttX0-00000000FAX-2CA1 for pgsql-hackers@postgresql.org; Tue, 11 Aug 2026 20:57:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67BKv2E12541686; Tue, 11 Aug 2026 16:57:02 -0400 From: Tom Lane To: Alexander Lakhin cc: pgsql-hackers , Andres Freund Subject: Re: plpython tests fail against python 3.14 under Valgrind In-reply-to: <2322557.1786409782@sss.pgh.pa.us> References: <2322557.1786409782@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 10 Aug 2026 20:56:22 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2541684.1786481822.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 11 Aug 2026 16:57:02 -0400 Message-ID: <2541685.1786481822@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > Anyway, I've confirmed that the attached patch makes the problem > go away here. Unless somebody wants to expend brain cells on > running the underlying issue to ground, I think we should just > apply this to the back branches and be happy. A variant plan > could be to do it like this #ifdef USE_VALGRIND and otherwise > keep the old code, but that seems unduly paranoid to me. A bit of excavation in our git history reminded me that our old behavior here was very intentional: Author: Tom Lane Branch: master Release: REL9_6_BR [62c8421e8] 2016-07-07 11:28:17 -0400 Reduce stack space consumption in tzload(). = While syncing our timezone code with IANA's updates in commit 1c1a7cbd= 6, I'd chosen not to adopt the code they conditionally compile under #ifd= ef ALL_STATE. The main thing that that drives is that the space for gmti= me and localtime timezone definitions isn't statically allocated, but is malloc'd on first use. I reasoned we didn't need that logic: we don't= have localtime() at all, and we always initialize TimeZone to GMT so we alw= ays need that one. But there is one other thing ALL_STATE does, which is = to make tzload() malloc its transient workspace instead of just declaring= it as a local variable. It turns out that that local variable occupies 7= 8K. Even worse is that, at least for common US timezone settings, there's = a recursive call to parse the "posixrules" zone name, making peak stack consumption to select a time zone upwards of 150K. That's an uncomfor= tably large fraction of our STACK_DEPTH_SLOP safety margin, and could result= in outright crashes if we try to reduce STACK_DEPTH_SLOP as has been disc= ussed recently. Furthermore, this means that the postmaster's peak stack consumption is several times that of a backend running typical queries (since, except on Windows, backends inherit the timezone GUC values an= d don't ever run this code themselves unless you do SET TIMEZONE). That= 's completely backwards from a safety perspective. = Hence, adopt the ALL_STATE rather than non-ALL_STATE variant of tzload= (), while not changing the other code aspects that symbol controls. The risk of an ENOMEM error from malloc() seems less than that of a SIGSEG= V from stack overrun. Now, we deleted the "posixrules" recursion logic in v13, so in all active branches the amount of stack space required is 70-something K not twice that. But re-reading this message, the postmaster vs. backends point still seems like a compelling safety argument. So I'd rather make master work like the old code instead of vice versa. Hence, what I'm now thinking is to malloc the space by default, but use a stack allocation if USE_VALGRIND, with a comment explaining that that masks an obscure valgrind-or-possibly-python bug; and to do it the same way in all branches. regards, tom lane