gdal icon indicating copy to clipboard operation
gdal copied to clipboard

Potential deadlock in `GDALAllRegister()`

Open artemp opened this issue 7 years ago • 3 comments

Potential deadlock in GDALAllRegister()

WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=9528)

This can be a "red herring" as sanitizer might not understanding code correctly ^

Steps to reproduce the problem.

#include <iostream>
#include <gdal_version.h>
#include <gdal_priv.h>
int main()
{
    std::cerr << "GDAL" << std::endl;
    GDALAllRegister();
    std::cerr << "Done" << std::endl;
    return 0;
}
"g++"   -fPIC -O0 -fno-inline -Wall -g -fsanitize=thread -fno-omit-frame-pointer   -I"$(GDAL_DIR)/include" -c -o "bin/gcc-8.2.0/debug/main.o" "main.cpp"

"g++" -L"$(GDAL_DIR)/lib" -Wl,-rpath -Wl,"$(GDAL_DIR)/lib" -Wl,-rpath-link -Wl,"$(GDAL_DIR)/lib" -o "bin/gcc-8.2.0/debug/gdal-bug" -Wl,--start-group "bin/gcc-8.2.0/debug/main.o"  -Wl,-Bstatic  -Wl,-Bdynamic -lgdal -Wl,--end-group -fPIC -g -fsanitize=thread

Output:

export TSAN_OPTIONS="second_deadlock_stack=1
./bin/gcc-8.2.0/debug/gdal-bug
GDAL
==================
WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=9528)
  Cycle in lock order graph: M55 (0x7fd0aec1d998) => M56 (0x7b1000000000) => M55

  Mutex M56 acquired here while holding mutex M55 in main thread:
    #0 pthread_mutex_lock <null> (libtsan.so.0+0x4016b)
    #1 CPLAcquireMutex /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1604 (libgdal.so.20+0xb9aeb3)
    #2 CPLCreateMutexInternal(bool, int) /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1581 (libgdal.so.20+0xb9aeb3)
    #3 __libc_start_main <null> (libc.so.6+0x2409a)

  Mutex M55 previously acquired by the same thread here:
    #0 pthread_mutex_lock <null> (libtsan.so.0+0x4016b)
    #1 CPLCreateOrAcquireMutexEx /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1418 (libgdal.so.20+0xb9aa64)
    #2 __libc_start_main <null> (libc.so.6+0x2409a)

  Mutex M55 acquired here while holding mutex M56 in main thread:
    #0 pthread_mutex_lock <null> (libtsan.so.0+0x4016b)
    #1 CPLCreateOrAcquireMutexEx /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1418 (libgdal.so.20+0xb9aa64)
    #2 __libc_start_main <null> (libc.so.6+0x2409a)

  Mutex M56 previously acquired by the same thread here:
    #0 pthread_mutex_lock <null> (libtsan.so.0+0x4016b)
    #1 CPLAcquireMutex /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1604 (libgdal.so.20+0xb9aeb3)
    #2 CPLCreateMutexInternal(bool, int) /home/artem/projects/gdal/gdal/port/cpl_multiproc.cpp:1581 (libgdal.so.20+0xb9aeb3)
    #3 __libc_start_main <null> (libc.so.6+0x2409a)

SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/usr/lib/x86_64-linux-gnu/libtsan.so.0+0x4016b) in pthread_mutex_lock
==================
Done
ThreadSanitizer: reported 1 warnings

Operating system

Ubuntu 18.10 64 bit

GDAL version and provenance

[master]

artemp avatar Nov 20 '18 17:11 artemp

Has this problem been addressed? I just ran into the same issue, reproduced with both clang and gcc thread sanitizers. I am using libgdal 3.5.1 (via opencv), on Ubuntu 22.10.

magnus-grandin avatar Aug 04 '23 06:08 magnus-grandin

I also have the same issue on Ubuntu 22.04.3 LTS.

Run cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release . -- The C compiler identification is GNU 12.2.0 -- The CXX compiler identification is GNU 12.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenCV: /usr (found version "4.6.0") -- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0") found components: program_options -- Found GTest: /usr/lib/x86_64-linux-gnu/cmake/GTest/GTestConfig.cmake (found version "1.12.1")
-- Build spdlog: 1.11.0 -- Found Threads: TRUE
-- Build type: Release -- Configuring done

There is no such issue for MacOS Ventura 13.4.1 (c) with Apple clang Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: arm64-apple-darwin22.5.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

lukasz-ziobron-tpl avatar Aug 16 '23 11:08 lukasz-ziobron-tpl

I confirm it's still an issue for Ubuntu 22.04.

jlblancoc avatar Nov 20 '23 18:11 jlblancoc