ThreadSanitizer reports lock-order-inversion running lldb on Ubuntu 14.04

We’ve been seeing intermittent test failures in some lit tests with this error message:

terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument

We’ve only seen it on a buildbot running on SLES 11 – we can’t reproduce it on our Ubuntu machines.

We build lldb with tsan turned on, and see a lock-order-inversion error with just a run/quit. Could this be the cause of our crash?

Build was done with ToT on Ubuntu 14.04, using clang 7.0.1 with this cmake line:

CC=clang CXX=clang++ cmake -G Ninja -DLLVM_USE_SANITIZER=Thread -DLLVM_ENABLE_LIBCXX=On …/llvm/

Output from the run:

TSAN_OPTIONS=second_deadlock_stack=1 bin/lldb

(lldb) quit

Some more info from my team:

Debugger:Clear() is calling StopEventHandlerThread followed by a m_listener_sp->Clear() and from what I can tell the EventHandlerThread isn’t fully stopped prior to the Clear being called.