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 1wtao7-0006Lr-1g for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Aug 2026 00:57:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wtan5-000WLc-1D for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Aug 2026 00:56:28 +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.96) (envelope-from ) id 1wtan5-000WLU-0G for pgsql-hackers@lists.postgresql.org; Tue, 11 Aug 2026 00:56:28 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wtan4-000000001YS-1T4X for pgsql-hackers@postgresql.org; Tue, 11 Aug 2026 00:56:27 +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 67B0uMnI2322558; Mon, 10 Aug 2026 20:56:22 -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: References: Comments: In-reply-to Alexander Lakhin message dated "Tue, 28 Jul 2026 08:00:01 +0300" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2322484.1786409724.0@sss.pgh.pa.us> Date: Mon, 10 Aug 2026 20:56:22 -0400 Message-ID: <2322557.1786409782@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2322484.1786409724.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Alexander Lakhin writes: > As buildfarm animal skink shows, upgrade to Python 3.14 breaks plpython > tests under Valgrind [1]: > =C2=A061/400 plpython - postgresql:plpython/regress ERROR=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 49.88s=C2=A0=C2=A0= exit status 1 Yeah, I can reproduce this here, using Fedora 43 (with python3-3.14.6-1.fc43.x86_64 and valgrind-3.27.1-1.fc43.x86_64). As you say, it doesn't reproduce on master; I didn't take the trouble to bisect. > It's also not reproduced on master, probably just because of a bit lesse= r > stack usage. I've bisected the anomaly and found what makes master pass > the tests: aeb07c55f. Actually, I think it's the other way around: master uses more stack. In v19, tzload() does this: union local_storage *lsp =3D malloc(sizeof *lsp); ... free(lsp); while in master it does this: union local_storage *lsp; union local_storage ls; lsp =3D &ls; That's a sizeable amount of stack getting chewed: (gdb) p sizeof(union local_storage) $1 =3D 72240 However, we surely don't invoke tzload() while running any Python code. What I think must be happening is that at postmaster start, or possibly backend start, we invoke tzload() while setting the timezone GUC, and this causes a bunch of stack pages to get allocated, more than we have in the v19 code path. Somehow, python and valgrind interact badly when there's not much pre-existing stack allocation. It's pretty unclear which one is to blame, but it seems like it can't be our fault. (Although ... surely the standard python executable invokes libpython with little pre-existing stack? If that doesn't trigger this problem, what are we doing differently?) 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. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="tzload-stack-hack-for-python.patch"; charset="us-ascii" Content-ID: <2322484.1786409724.2@sss.pgh.pa.us> Content-Description: tzload-stack-hack-for-python.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/timezone/localtime.c b/src/timezone/localtime.c index fb04b4cf6bf..1a8088b520c 100644 --- a/src/timezone/localtime.c +++ b/src/timezone/localtime.c @@ -588,17 +588,10 @@ tzloadbody(char const *name, char *canonname, struct= state *sp, bool doextend, int tzload(char const *name, char *canonname, struct state *sp, bool doextend= ) { - union local_storage *lsp =3D malloc(sizeof *lsp); + union local_storage ls; + union local_storage *lsp =3D &ls; = - if (!lsp) - return errno; - else - { - int err =3D tzloadbody(name, canonname, sp, doextend, lsp); - - free(lsp); - return err; - } + return tzloadbody(name, canonname, sp, doextend, lsp); } = static bool ------- =_aaaaaaaaaa0--