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 1rVy8j-002RJV-Ne for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Feb 2024 18:19:50 +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 1rVy8i-00F4Ut-Q1 for pgsql-bugs@arkaria.postgresql.org; Fri, 02 Feb 2024 18:19:48 +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.94.2) (envelope-from ) id 1rVy8i-00F4Ub-Gf for pgsql-bugs@lists.postgresql.org; Fri, 02 Feb 2024 18:19:48 +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.94.2) (envelope-from ) id 1rVy8g-0057qh-5Q for pgsql-bugs@lists.postgresql.org; Fri, 02 Feb 2024 18:19:47 +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 412IJgwT3222817; Fri, 2 Feb 2024 13:19:42 -0500 From: Tom Lane To: Christian Maurer cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe In-reply-to: References: <18312-bbbabc8113592b78@postgresql.org> <3154181.1706888936@sss.pgh.pa.us> Comments: In-reply-to Christian Maurer message dated "Fri, 02 Feb 2024 17:27:24 +0100" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3222761.1706897954.0@sss.pgh.pa.us> Date: Fri, 02 Feb 2024 13:19:42 -0500 Message-ID: <3222816.1706897982@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="us-ascii" Content-ID: <3222761.1706897954.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Christian Maurer writes: >> I wondered whether we needed to introduce a critical section >> to prevent multiple threads from calling that concurrently, >> even though its docs allege you shouldn't have to. Perhaps >> it's thread-safe except on Windows? > This would explain, why I could not reproduce the error on Red Hat Enter= prise Linux. Are you in a position to try a source-code patch? The attached is very quick-and-dirty, but if it resolves your problem then we could turn it into something respectable. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="avoid-concurrent-bindtextdomain-calls-wip.patch"; charset="us-ascii" Content-ID: <3222761.1706897954.2@sss.pgh.pa.us> Content-Description: avoid-concurrent-bindtextdomain-calls-wip.patch diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index 47a28b0a3a..8906dae892 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -1243,12 +1243,17 @@ libpq_binddomain(void) #endif const char *ldir; + pglock_thread(); + /* 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; + + pgunlock_thread(); + #ifdef WIN32 SetLastError(save_errno); #else ------- =_aaaaaaaaaa0--