[SERVER-3786] Segfault on unloading libmongoclient.so (built as a shared lib) in a thread other than the main thread Created: 08/Sep/11  Updated: 29/Feb/12  Resolved: 21/Jan/12

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Arseny Vakhrushev Assignee: Mathias Stearn
Resolution: Cannot Reproduce Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
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.


Attachments: File test.cpp    
Operating System: Linux
Participants:

 Description   

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



 Comments   
Comment by Mathias Stearn [ 17/Oct/11 ]

Due to some build issues I was previously unable to build the shared client. As of a fix I just pushed to master I am now able to build.

I am not able to reproduce this using the latest code. Could you try a fresh checkout and see if it has been fixed for you as well? If not, please include some more info on your environment such as kernel, g++ and glibc versions.

$ ./a.out && echo it worked
Loading library...
Closing library...
it worked

Comment by Arseny Vakhrushev [ 05/Oct/11 ]

No progress on this issue?

Generated at Thu Feb 08 03:04:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.