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 1wKdhv-001CnA-07 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 May 2026 14:58:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKdht-00HUj6-28 for pgsql-hackers@arkaria.postgresql.org; Wed, 06 May 2026 14:58:37 +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 1wKdht-00HUiy-1G for pgsql-hackers@lists.postgresql.org; Wed, 06 May 2026 14:58:37 +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 1wKdhp-00000000qAU-2Ezc for pgsql-hackers@postgresql.org; Wed, 06 May 2026 14:58:37 +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 646EwRcl771393; Wed, 6 May 2026 10:58:27 -0400 From: Tom Lane To: Andrew Dunstan cc: Alexander Lakhin , Nishant Sharma , Shruthi Gowda , Mahendra Singh Thalor , Fujii Masao , PostgreSQL Development Subject: Re: [BUG] CRASH: ECPGprepared_statement() and ECPGdeallocate_all() when connection is NULL In-reply-to: <53e7527c-eb86-4ef5-a3fb-df98cd9c973a@dunslane.net> References: <75460b3c-2! 55d-47eb-b889-d99de38e6758@gmail.com> <699623.1778013161@sss.pgh.pa.us> <53e7527c-eb! 86-4ef5-a3fb-df98cd9c973a@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Wed, 06 May 2026 07:55:10 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <771391.1778079507.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 06 May 2026 10:58:27 -0400 Message-ID: <771392.1778079507@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Dunstan writes: > Attached is a patch with the fix, courtesy of claude. It's a slight = > behaviour change: Yeah. So we could either do something like this, or say that the test case is buggy and needs to provide its own mutexes, per the existing comment - * if no connection in TSD for this thread, get the global defaul= t - * connection and hope the user knows what they're doing (i.e. us= ing - * their own mutex to protect that connection from concurrent acc= esses On the whole I think I favor the behavior change. We might get some complaints, but it just seems a lot safer to redefine it like this. Either way, it seems like some documentation adjustments are called for. As far as the patch itself goes, I'd be inclined to pull the preparatory step ecpg_pthreads_init(); /* ensure actual_connection_key is valid= */ into the new ecpg_default_connection() subroutine, especially since its proposed comment doesn't mention that prerequisite. regards, tom lane