Commit d8386e34 authored by Tianjiao Yin's avatar Tianjiao Yin Committed by Andrew Cox

print better error message

Summary:
before:

E0203 12:32:34.548096 3354863 [admonitor-local] Singleton.cpp:72] Singleton of type N8facebook12configerator22ConfigeratorStaticDataE has a living reference at destroyInstances time; beware! Raw pointer is 0x7fd6ccc81000. It is very likely that some other singleton is holding a shared_ptr to it. Make dependencies between these singletons are properly defined.

after:

E0203 13:48:09.013022 3913115 Singleton.cpp:72] Singleton of type facebook::configerator::ConfigeratorStaticData has a living reference at destroyInstances time; beware! Raw pointer is 0x7f6f7dc4c000. It is very likely that some other singleton is holding a shared_ptr to it. Make dependencies between these singletons are properly defined.

Test Plan: run it

Reviewed By: chip@fb.com

Subscribers: folly-diffs@, yfeldblum

FB internal diff: D1822466

Signature: t1:1822466:1423000686:345f40fa706701476256a7157468521bc69166a0
parent 46fd8dca
No related merge requests found
...@@ -69,7 +69,7 @@ void SingletonVault::destroyInstance(SingletonMap::iterator entry_it) { ...@@ -69,7 +69,7 @@ void SingletonVault::destroyInstance(SingletonMap::iterator entry_it) {
auto wait_result = entry.destroy_baton->timed_wait( auto wait_result = entry.destroy_baton->timed_wait(
std::chrono::steady_clock::now() + kDestroyWaitTime); std::chrono::steady_clock::now() + kDestroyWaitTime);
if (!wait_result) { if (!wait_result) {
LOG(ERROR) << "Singleton of type " << type.name() << " has a living " LOG(ERROR) << "Singleton of type " << type.prettyName() << " has a living "
<< "reference at destroyInstances time; beware! Raw pointer " << "reference at destroyInstances time; beware! Raw pointer "
<< "is " << entry.instance_ptr << ". It is very likely that " << "is " << entry.instance_ptr << ". It is very likely that "
<< "some other singleton is holding a shared_ptr to it. Make " << "some other singleton is holding a shared_ptr to it. Make "
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
#include <folly/Hash.h> #include <folly/Hash.h>
#include <folly/Memory.h> #include <folly/Memory.h>
#include <folly/RWSpinLock.h> #include <folly/RWSpinLock.h>
#include <folly/Demangle.h>
#include <folly/io/async/Request.h> #include <folly/io/async/Request.h>
#include <algorithm> #include <algorithm>
...@@ -162,13 +163,13 @@ class TypeDescriptor { ...@@ -162,13 +163,13 @@ class TypeDescriptor {
return *this; return *this;
} }
std::string name() const { std::string prettyName() const {
std::string ret = ti_.name(); auto ret = demangle(ti_.name());
if (tag_ti_ != std::type_index(typeid(DefaultTag))) { if (tag_ti_ != std::type_index(typeid(DefaultTag))) {
ret += "/"; ret += "/";
ret += tag_ti_.name(); ret += demangle(tag_ti_.name());
} }
return ret; return ret.toStdString();
} }
friend class TypeDescriptorHasher; friend class TypeDescriptorHasher;
...@@ -436,7 +437,7 @@ class SingletonVault { ...@@ -436,7 +437,7 @@ class SingletonVault {
auto it = singletons_.find(type); auto it = singletons_.find(type);
if (it == singletons_.end()) { if (it == singletons_.end()) {
throw std::out_of_range(std::string("non-existent singleton: ") + throw std::out_of_range(std::string("non-existent singleton: ") +
type.name()); type.prettyName());
} }
return it->second.get(); return it->second.get();
...@@ -457,7 +458,7 @@ class SingletonVault { ...@@ -457,7 +458,7 @@ class SingletonVault {
// it if it was set by current thread anyways. // it if it was set by current thread anyways.
if (entry->creating_thread == std::this_thread::get_id()) { if (entry->creating_thread == std::this_thread::get_id()) {
throw std::out_of_range(std::string("circular singleton dependency: ") + throw std::out_of_range(std::string("circular singleton dependency: ") +
type.name()); type.prettyName());
} }
std::lock_guard<std::mutex> entry_lock(entry->mutex); std::lock_guard<std::mutex> entry_lock(entry->mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment