Skip to content

Commit

Permalink
Shutdown globalBucketLogger at end of ep_engine_benchmarks
Browse files Browse the repository at this point in the history
On macOS the following exception is thrown at the end of
ep_engine_benchmarks:

    libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument

The issue is an instance of the 'static (de)initialization order
fiacso' - globalBucketLogger (a shared_ptr) is not destroyed before
the process exits - it is only cleaned up by the C++ runtime. However,
another singleton object - spdlog::registry which the BucketLogget
dtor uses to unregister itself - has already been destroyed. As such
an exception is thrown attempting to lock a mutex which has already
been destroyed:

    (lldb) bt
      * frame #0: 0x00007fff6e84b1f6 libc++abi.dylib` __cxa_throw =
        frame #1: 0x00007fff6e81e7af libc++.1.dylib` std::__1::__throw_system_error(int, char const*)  + 77
        frame #2: 0x00007fff6e810c93 libc++.1.dylib` std::__1::mutex::lock()  + 29
        frame #3: 0x000000010068fd75 libmemcached_logger.1.0.0.dylib` spdlog::details::registry::drop(...) [inlined] std::__1::lock_guard<std::__1::mutex>::lock_guard(__m=0x00000001006a3c20)  + 21 at __mutex_base:104
        frame #4: 0x000000010068fd70 libmemcached_logger.1.0.0.dylib` spdlog::details::registry::drop(..&) [inlined] std::__1::lock_guard<std::__1::mutex>::lock_guard(__m=0x00000001006a3c20)  at __mutex_base:104
        frame #5: 0x000000010068fd70 libmemcached_logger.1.0.0.dylib` spdlog::details::registry::drop(this=0x00000001006a3c20, logger_name="globalBucketLogger")  + 16 at registry.h:173
        frame #6: 0x000000010004608f ep_engine_benchmarks` BucketLogger::~BucketLogger() [inlined] BucketLogger::unregister(this=<unavailable>)  + 47 at bucket_logger.cc:81
        frame #7: 0x000000010004607b ep_engine_benchmarks` BucketLogger::~BucketLogger(this=0x0000000105047080)  + 27 at bucket_logger.cc:35
        frame #8: 0x00000001000461ee ep_engine_benchmarks` BucketLogger::~BucketLogger() [inlined] BucketLogger::~BucketLogger(this=0x0000000105047080)  + 14 at bucket_logger.cc:34
        frame #9: 0x00000001000461e9 ep_engine_benchmarks` BucketLogger::~BucketLogger(this=0x0000000105047080)  + 9 at bucket_logger.cc:34
        frame #10: 0x0000000100046e21 ep_engine_benchmarks` std::__1::shared_ptr<BucketLogger>::~shared_ptr() [inlined] std::__1::__shared_count::__release_shared(this=0x00000001052f5540)  + 49 at memory:3490
        frame #11: 0x0000000100046e18 ep_engine_benchmarks` std::__1::shared_ptr<BucketLogger>::~shared_ptr() [inlined] std::__1::__shared_weak_count::__release_shared(this=0x00000001052f5540)  at memory:3532
        frame #12: 0x0000000100046e18 ep_engine_benchmarks` std::__1::shared_ptr<BucketLogger>::~shared_ptr() [inlined] std::__1::shared_ptr<BucketLogger>::~shared_ptr(this=<unavailable>)  at memory:4468
        frame #13: 0x0000000100046e18 ep_engine_benchmarks` std::__1::shared_ptr<BucketLogger>::~shared_ptr(this=<unavailable>)  + 40 at memory:4466
        frame #14: 0x00007fff70935eed libsystem_c.dylib` __cxa_finalize_ranges  + 351
        frame #15: 0x00007fff709361fe libsystem_c.dylib` exit  + 55
        frame #16: 0x00007fff7088901c libdyld.dylib` start  + 8

Fix by manually resetting globalBucketLogger() before the end of
main().

Change-Id: I8abeb71c77580e0a4ef1342612d3c7af084de122
Reviewed-on: http://review.couchbase.org/104331
Tested-by: Build Bot <[email protected]>
Reviewed-by: Ben Huddleston <[email protected]>
  • Loading branch information
daverigby committed Feb 1, 2019
1 parent f057e5a commit e1da9f4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion engines/ep/benchmarks/ep_engine_benchmarks_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ int main(int argc, char** argv) {
* If we get a 0 return, then return 1 from main to signal an error
* occurred.
*/
return ::benchmark::RunSpecifiedBenchmarks() == 0 ? 1 : 0;
auto result = ::benchmark::RunSpecifiedBenchmarks();

globalBucketLogger.reset();

return result == 0 ? 1 : 0;
}

0 comments on commit e1da9f4

Please sign in to comment.