Segfault on unloading libmongoclient.so (built as a shared lib) in a thread other than the main thread

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Internal Client
    • None
    • Environment:
      Gentoo Linux x64 (mongoclient is built as a shared lib on Gentoo). No such issue on Arch where it's built as a static lib.
    • Linux
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Segfault when a thread other than the main thread of execution de-initializes tls (tsd). mongoclient.so should be dlopen-ed in that thread beforehand. Steps to reproduce:

      create thread
      dlopen('libmongoclient.so')
      dlclose('libmongoclient.so')
      join thread
      observe segfault

      Reproduce using the attached file:
      $ g++ -o test test.cpp -lpthread -ldl
      $ ./test
      Loading library...
      Closing library...
      Segmentation fault

      GDB output:
      [Thread debugging using libthread_db enabled]
      [New Thread 0x7ffff6eb0700 (LWP 15768)]
      Loading library...
      Closing library...

      Program received signal SIGSEGV, Segmentation fault.
      [Switching to Thread 0x7ffff6eb0700 (LWP 15768)]
      0x00007ffff5f2e840 in ?? ()
      (gdb) bt
      #0 0x00007ffff5f2e840 in ?? ()
      #1 0x00007ffff7bc9211 in __nptl_deallocate_tsd () from /lib64/libpthread.so.0
      #2 0x00007ffff7bc9be8 in start_thread () from /lib64/libpthread.so.0
      #3 0x00007ffff6f8076d in clone () from /lib64/libc.so.6
      (gdb)

      Try to change 'libmongoclient.so' to any other .so (e.g. libneon.so), and the problem is gone.

      The original source of the bug discovery was: Lua in a thread + LuaMongo driver.
      1. a Lua environment is started in a separate thread
      2. require 'mongo'
      3. mongo.so loads libmongoclient.so through the call to dlopen()
      4. crash when the thread terminates

            Assignee:
            Mathias Stearn
            Reporter:
            Arseny Vakhrushev
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: