Re: Thread-unsafe coding in ecpg
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Meskes <meskes@postgresql.org>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2019-01-20T17:30:48Z
Lists: pgsql-hackers
Michael Meskes <meskes@postgresql.org> writes: >> No, we shouldn't use setlocale(), because it clearly is hazardous >> even on platforms where it doesn't fail outright. I don't see >> anything so wrong with just documenting the hazard. The situation > Actually I meant using setlocale() and documenting that it must not be > used with threads, or document it must not be used with locales? I tend to think that has more downside than upside, in situations where people don't read the manual closely and try to do it anyway. First, there's the probable crash if setlocale() is thread-unsafe. (Though the lack of previous reports suggests that on most platforms, it isn't.) Second, if the program is indeed trying to run with non-C LC_NUMERIC, using setlocale() will have unsynchronized, hard-to-debug side effects on other threads. Not using it will have no downside at all if ecpg isn't trying to read numeric data, while if it does do so, the failures will be reproducible and easy to understand/debug. Admittedly, removing the setlocale() call will be a net negative for single-threaded applications, which are likely the majority. But I don't know any safe way to tell whether the app is multi threaded. On the third hand, the lack of previous reports suggests that maybe this whole thing is seldom a problem in practice. Maybe we should just use uselocale() where available and otherwise hope it's OK to keep on doing what we were doing. regards, tom lane
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