Re: Thread-unsafe coding in ecpg
Michael Meskes <meskes@postgresql.org>
From: Michael Meskes <meskes@postgresql.org>
To: Tom Lane <tgl@sss.pgh.pa.us>, pgsql-hackers@lists.postgresql.org
Date: 2019-01-19T19:15:37Z
Lists: pgsql-hackers
Attachments
- ecpg_locale.diff (text/x-patch) patch
> So my conclusion is that this version of setlocale() has some > thread-safety issues. I was all set to go file a bug report > when I noticed this in the POSIX spec for setlocale: > > The setlocale() function need not be thread-safe. > > as well as this: > > The global locale established using setlocale() shall only be > used > in threads for which no current locale has been set using > uselocale() or whose current locale has been set to the global > locale using uselocale(LC_GLOBAL_LOCALE). This one was new to me. > IOW, not only is setlocale() not necessarily thread-safe itself, > but using it to change locales in a multithread program is seriously > unsafe because of concurrent effects on other threads. Agreed. > Therefore, it's plain crazy for ecpg to be calling setlocale() inside > threaded code. It looks to me like what ecpg is doing is trying to > defend > itself against non-C LC_NUMERIC settings, which is laudable, but this > implementation of that is totally unsafe. > > Don't know what's the best way out of this. The simplest thing would > be to just remove that code and document that you'd better run ecpg > in LC_NUMERIC locale, but it'd be nice if we could do better. How about attached patch? According to my manpages it should only affect the calling threat. I only tested it on my own system so far. Could you please have a look and/or test on other systems? Michael -- Michael Meskes Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) Meskes at (Debian|Postgresql) dot Org Jabber: michael at xmpp dot meskes dot org VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL
Commits
-
Remove _configthreadlocale() calls in ecpg test suite.
- e3565fd61cee 12.0 landed
-
Remove infinite-loop hazards in ecpg test suite.
- d5a1fde39726 12.0 landed
- fbf5395cb1ea 9.5.16 landed
- 6d6333745b11 9.4.21 landed
- adc2553b7069 9.6.12 landed
- 5b5cb3b0eb31 10.7 landed
- 28868f77b6cb 11.2 landed
-
Blind attempt to fix _configthreadlocale() failures on MinGW.
- 773f594408b9 9.4.21 landed
- 7ac0e71aa623 9.5.16 landed
- 1d334ab6e0b5 9.6.12 landed
- dd815a94ccf5 10.7 landed
- b620cf2d4762 11.2 landed
- 2cf91ccb73ce 12.0 landed
-
Avoid thread-safety problem in ecpglib.
- f305e8457d1e 11.2 landed
- eb3e90cad1e4 9.6.12 landed
- c9ff6cbfc472 9.4.21 landed
- 844d91fd6496 9.5.16 landed
- 6106f9dd71ff 10.7 landed
- 8eb4a9312c95 12.0 landed
-
Second try at fixing ecpglib thread-safety problem.
- ee27584c4a40 12.0 landed