Repository navigation
Conversation
We previously supposed that it was okay for different threads to call bindtextdomain() concurrently (cf. commit 1f655fd). It now emerges that there's at least one gettext implementation in which that triggers an abort() crash, so let's stop doing that. Add mutexes guarding libpq's and ecpglib's calls, which are the only ones that need worry about multithreaded callers. Note: in libpq, we could perhaps have piggybacked on default_threadlock() to avoid defining a new mutex variable. I judge that not terribly safe though, since libpq_gettext could be called from code that is holding the default mutex. If that were the first such call in the process, it'd fail. An extra mutex is cheap insurance against unforeseen interactions. Per bug #18312 from Christian Maurer. Back-patch to all supported versions. Discussion: https://postgr.es/m/18312-bbbabc8113592b78@postgresql.org Discussion: https://postgr.es/m/264860.1707163416@sss.pgh.pa.us Cloudberry: the merge of REL_16_9 (0f4cf8d) brought in only this commit's removal of ldir's declaration from the outer block of libpq_binddomain(), not the mutex or the declaration's new place. The function was left without the lock and using ldir undeclared, which breaks any build with ENABLE_NLS. The ecpglib half came through intact, so only fe-misc.c changes here. Assisted-by: Claude Code (cherry picked from commit 52afe56)
|
We accidentally found this issue at #1940. Some context for reviewersthis changes nothing in today's builds. The point is to bring the function back in line with upstream. The REL_16_9 merge (0f4cf8d) kept only part of 52afe56, leaving the function without its mutex and using ldir undeclared. Matching upstream again means future PostgreSQL minor-version merges will not conflict here, and if NLS is ever turned back on, the code builds and carries upstream's fix for bug #18312. |
leborchuk
left a comment
There was a problem hiding this comment.
LGTM, bugfix from upstream
| * might as well do it the same way everywhere. | ||
| */ | ||
| static volatile bool already_bound = false; | ||
| static pthread_mutex_t binddomain_mutex = PTHREAD_MUTEX_INITIALIZER; |
There was a problem hiding this comment.
I provided suggested changes to guard the mutex declaration and both pthread_mutex_lock() / pthread_mutex_unlock() calls with #ifdef ENABLE_THREAD_SAFETY. libpq-int.h includes the pthread headers only when thread safety is enabled, so this change fails to compile with --enable-nls --disable-thread-safety.
| * might as well do it the same way everywhere. | ||
| */ | ||
| static volatile bool already_bound = false; | ||
| static pthread_mutex_t binddomain_mutex = PTHREAD_MUTEX_INITIALIZER; |
There was a problem hiding this comment.
| static pthread_mutex_t binddomain_mutex = PTHREAD_MUTEX_INITIALIZER; | |
| +#ifdef ENABLE_THREAD_SAFETY | |
| static pthread_mutex_t binddomain_mutex = PTHREAD_MUTEX_INITIALIZER; | |
| +#endif |
| ldir = LOCALEDIR; | ||
| bindtextdomain(PG_TEXTDOMAIN("libpq"), ldir); | ||
| already_bound = true; | ||
| (void) pthread_mutex_lock(&binddomain_mutex); |
There was a problem hiding this comment.
| (void) pthread_mutex_lock(&binddomain_mutex); | |
| +#ifdef ENABLE_THREAD_SAFETY | |
| (void) pthread_mutex_lock(&binddomain_mutex); | |
| +#endif |
| already_bound = true; | ||
| } | ||
|
|
||
| (void) pthread_mutex_unlock(&binddomain_mutex); |
There was a problem hiding this comment.
| (void) pthread_mutex_unlock(&binddomain_mutex); | |
| +#ifdef ENABLE_THREAD_SAFETY | |
| (void) pthread_mutex_unlock(&binddomain_mutex); | |
| +#endif |
We previously supposed that it was okay for different threads to call bindtextdomain() concurrently (cf. commit 1f655fd). It now emerges that there's at least one gettext implementation in which that triggers an abort() crash, so let's stop doing that. Add mutexes guarding libpq's and ecpglib's calls, which are the only ones that need worry about multithreaded callers.
Note: in libpq, we could perhaps have piggybacked on default_threadlock() to avoid defining a new mutex variable. I judge that not terribly safe though, since libpq_gettext could be called from code that is holding the default mutex. If that were the first such call in the process, it'd fail. An extra mutex is cheap insurance against unforeseen interactions.
Per bug #18312 from Christian Maurer. Back-patch to all supported versions.
Discussion: https://postgr.es/m/18312-bbbabc8113592b78@postgresql.org
Discussion: https://postgr.es/m/264860.1707163416@sss.pgh.pa.us
Cloudberry: the merge of REL_16_9 (0f4cf8d) brought in only this commit's removal of ldir's declaration from the outer block of libpq_binddomain(), not the mutex or the declaration's new place. The function was left without the lock and using ldir undeclared, which breaks any build with ENABLE_NLS. The ecpglib half came through intact, so only fe-misc.c changes here.
Assisted-by: Claude Code
(cherry picked from commit 52afe56)
Fixes #ISSUE_Number
What does this PR do?
Type of Change
Breaking Changes
Test Plan
make installcheckmake -C src/test installcheck-cbdb-parallelImpact
Performance:
User-facing changes:
Dependencies:
Checklist
Additional Context
CI Skip Instructions