pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Christian Maurer <c.maurer@gmx.at>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
Date: Fri, 02 Feb 2024 13:19:42 -0500
Message-ID: <3222816.1706897982@sss.pgh.pa.us> (raw)
In-Reply-To: <trinity-31b9e9ec-519e-4c85-8029-632609642c16-1706891244274@3c-app-gmx-bap32>
References: <18312-bbbabc8113592b78@postgresql.org>
	<trinity-bf4e8296-ed0b-48cd-8a8c-86135d8dd5d9-1706869306101@3c-app-gmx-bap04>
	<3154181.1706888936@sss.pgh.pa.us>
	<trinity-31b9e9ec-519e-4c85-8029-632609642c16-1706891244274@3c-app-gmx-bap32>

Christian Maurer <c.maurer@gmx.at> 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 Enterprise 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

Attachments:

  [text/x-diff] avoid-concurrent-bindtextdomain-calls-wip.patch (578B, ../3222816.1706897982@sss.pgh.pa.us/2-avoid-concurrent-bindtextdomain-calls-wip.patch)
  download | inline diff:
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

view thread (7+ messages)  latest in thread

Message-ID: <3222816.1706897982@sss.pgh.pa.us>
Permalink:  ../3222816.1706897982@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3222816.1706897982@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, c.maurer@gmx.at, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18312: libpq: PQsetdbLogin() not thread-safe
  In-Reply-To: <3222816.1706897982@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox