Possible race condition when using GDAL/PROJ
Description
A test seemingly unrelated to my changes (!797 (merged)) fails
In the following test, https://cdash.orfeo-toolbox.org/testDetails.php?test=27332167&build=60372, we see that the execution of ioTvDEMToImageGeneratorFromImageTest
fails with the following backtrace
*** glibc detected *** /builds/otb/build/bin/otbDEMTestDriver: double free or corruption (!prev): 0x00000000026e0200 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x75e5e)[0x7f6288fede5e]
/lib64/libc.so.6(+0x78cf0)[0x7f6288ff0cf0]
/usr/lib64/libstdc++.so.6(_ZNSs6assignERKSs+0x85)[0x7f62895c0565]
/builds/otb/xdk/lib/libproj.so.17(proj_context_get_database_path+0x77)[0x7f62881630e7]
/builds/otb/xdk/lib/libgdal.so.27(+0x4d473a)[0x7f6289cfd73a]
/builds/otb/xdk/lib/libgdal.so.27(_Z20OSRGetProjTLSContextv+0x9)[0x7f6289cfd8b9]
/builds/otb/xdk/lib/libgdal.so.27(_ZN9OGRProjCT9TransformEiPdS0_S0_S0_Pi+0x25f)[0x7f6289d1150f]
/builds/otb/xdk/lib/libgdal.so.27(_ZN27OGRCoordinateTransformation9TransformEiPdS0_S0_Pi+0xc1)[0x7f6289d12f51]
/builds/otb/xdk/lib/libOTBGdalAdapters-7.2.so.1(_ZNK3otb24CoordinateTransformation9TransformERKSt5tupleIJdddEE+0x56)[0x7f628cb7a956]
/builds/otb/build/bin/otbDEMTestDriver[0x414efb]
/builds/otb/build/bin/otbDEMTestDriver[0x417afd]
/builds/otb/build/bin/otbDEMTestDriver[0x427468]
/builds/otb/build/bin/otbDEMTestDriver(_ZN3itk11ImageSourceIN3otb5ImageIdLj2EEEE16ThreaderCallbackEPv+0xec)[0x417f6c]
/builds/otb/xdk/lib/libITKCommon-4.13.so.1(_ZN3itk13MultiThreader17SingleMethodProxyEPv+0x7)[0x7f628bd37e17]
/lib64/libpthread.so.0(+0x7aa1)[0x7f628b32daa1]
/lib64/libc.so.6(clone+0x6d)[0x7f6289060c4d]
Which, passed to c++filt
translates as:
======= Backtrace: =========
/lib64/libc.so.6(+0x75e5e)[0x7f6288fede5e]
/lib64/libc.so.6(+0x78cf0)[0x7f6288ff0cf0]
/usr/lib64/libstdc++.so.6(std::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)+0x85)[0x7f62895c0565]
/builds/otb/xdk/lib/libproj.so.17(proj_context_get_database_path+0x77)[0x7f62881630e7]
/builds/otb/xdk/lib/libgdal.so.27(+0x4d473a)[0x7f6289cfd73a]
/builds/otb/xdk/lib/libgdal.so.27(OSRGetProjTLSContext()+0x9)[0x7f6289cfd8b9]
/builds/otb/xdk/lib/libgdal.so.27(OGRProjCT::Transform(int, double*, double*, double*, double*, int*)+0x25f)[0x7f6289d1150f]
/builds/otb/xdk/lib/libgdal.so.27(OGRCoordinateTransformation::Transform(int, double*, double*, double*, int*)+0xc1)[0x7f6289d12f51]
/builds/otb/xdk/lib/libOTBGdalAdapters-7.2.so.1(otb::CoordinateTransformation::Transform(std::tuple<double, double, double> const&) const+0x56)[0x7f628cb7a956]
/builds/otb/build/bin/otbDEMTestDriver[0x414efb]
/builds/otb/build/bin/otbDEMTestDriver[0x417afd]
/builds/otb/build/bin/otbDEMTestDriver[0x427468]
/builds/otb/build/bin/otbDEMTestDriver(itk::ImageSource<otb::Image<double, 2u> >::ThreaderCallback(void*)+0xec)[0x417f6c]
/builds/otb/xdk/lib/libITKCommon-4.13.so.1(itk::MultiThreader::SingleMethodProxy(void*)+0x7)[0x7f628bd37e17]
/lib64/libpthread.so.0(+0x7aa1)[0x7f628b32daa1]
/lib64/libc.so.6(clone+0x6d)[0x7f6289060c4d]
I've run the test through a sanitized (address+undefined) version of OTB, but could not reproduce the error. Neither PROG nor GDAL where compiled with sanitization on.
After a bit of googling, I wonder if this is not the result of a possible data race on OGRCoordinateTransformation
.
http://osgeo-org.1560.x6.nabble.com/gdal-dev-OGRCoordinateTransformation-Thread-Safety-td5421166.html and other messages on that mailing list seem to say that this object is not thread safe. I'm not sure a mutex would do. I'm under the impression it's better to have a different instance of the object in each thread we have.
It's just wild guesses.
Steps to reproduce
Unfortunately if my guesses are correct it'll quite hard to reproduce.
Configuration information
gitlab-ci debian runner, on MR !797 (merged) (~ 8.0 alpha)