Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAl3Q-0003t3-6o for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Jan 2022 03:57:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAl2t-0001ap-Dn for pgsql-bugs@arkaria.postgresql.org; Fri, 21 Jan 2022 03:57:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAl2t-0001ag-5B for pgsql-bugs@lists.postgresql.org; Fri, 21 Jan 2022 03:57:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAl2p-0006G0-BC for pgsql-bugs@lists.postgresql.org; Fri, 21 Jan 2022 03:57:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 20L3uvna1105078; Thu, 20 Jan 2022 22:56:57 -0500 From: Tom Lane To: Liam Bowen cc: pgsql-bugs@lists.postgresql.org Subject: Re: Further information on BUG #17299: Exit code 3 when open connections concurrently (PQisthreadsafe() == 1) In-reply-to: References: Comments: In-reply-to Liam Bowen message dated "Thu, 20 Jan 2022 21:00:22 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1105076.1642737417.1@sss.pgh.pa.us> Date: Thu, 20 Jan 2022 22:56:57 -0500 Message-ID: <1105077.1642737417@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Liam Bowen writes: > I used the EnterpriseDB installer for several versions, and narrowed down > the bug as being introduced between 13.5 and 14.1. Then I used git bisect > to narrow down which revision actually introduced the bug. Each time, I > would build libpq and copy the DLL into the same directory as my executable > and verify that my build of libpq was being loaded. Eventually my bisection > pointed to 52a1022. Hmmm .... > Here is a debugging session: > https://gist.github.com/hut8/3b25e6a581a600589bdc62644734de18. So as with the original bug #17299 report, this is showing an abort() failure inside libintl, although yours is in a slightly different place. It would be interesting to look into the libintl code and try to understand what it's seeing as wrong. Can you get debug data out of those stack frames? My gut feeling right now is that the reason 52a1022 tickles this is that it causes us to invoke gettext() in the normal, successful PQconnect code paths. I'm too tired to go look, but I suspect that before that patch, a non-error connection would never perform any message translations (or at least would not do so in the most basic cases). So that would result in us hitting gettext() much more heavily than before. Given that you're only seeing this when performing concurrent connections (or at least that's how I understood what you said), I'm eyeing libpq_binddomain with a bit of suspicion. Does it help to move down the update of already_bound, like this? const char *ldir; - already_bound = true; /* No relocatable lookup here because the binary could be anywhere */ ldir = getenv("PGLOCALEDIR"); if (!ldir) ldir = LOCALEDIR; bindtextdomain(PG_TEXTDOMAIN("libpq"), ldir); + already_bound = true; #ifdef WIN32 SetLastError(save_errno); #else errno = save_errno; #endif My thought here is that if two threads went through this code at about the same time, it'd be possible for one of them to decide that the bindtextdomain call had already happened when it had not. That could lead to that thread calling gettext and then the other one calling bindtextdomain later than that; and maybe libintl's response to that is as unfriendly as abort(). The above quick-hack change would result in both threads calling bindtextdomain, which I'm guessing libintl is prepared to cope with (at least, its docs claim bindtextdomain is "MT-Safe"). If it isn't really, then we might have to additionally add a critical section here. regards, tom lane