Fix ASAN failures in OBCClient
authorAndrii Grynenko <andrii@fb.com>
Thu, 22 Jan 2015 19:07:08 +0000 (11:07 -0800)
committerwoo <woo@fb.com>
Mon, 2 Feb 2015 21:12:26 +0000 (13:12 -0800)
Summary:
This also adds a dependency from all folly::Singletons on RequestContext. Better fix would probaly be to switch RequestContext to be managed by folly::Singleton, however that would require us to switch all singletons which use it to be folly::Singletons too.

Facebook:
Making sure we initialize SR singletons when OBCClient singleton is created, so that SR is destoyed after OBCClient.

Test Plan:
fbconfig -r --sanitize=address --platform-all=gcc-4.8.1-glibc-2.17 dragon/
fbmake runtests

Reviewed By: meyering@fb.com, davejwatson@fb.com

Subscribers: trunkagent, folly-diffs@, meyering

FB internal diff: D1796847

Tasks: 5986816

Signature: t1:1796847:1421954531:e9ec177d5289a33c12fe0947426d89963c8e262c

folly/experimental/Singleton.cpp
folly/experimental/Singleton.h

index 68f531a6b778b91fc8bdc44a21a14b8d661d016e..f77c5c520bf0f39d3f33a0d7b27252a883dab749 100644 (file)
@@ -81,6 +81,8 @@ SingletonVault* SingletonVault::singleton() {
 }
 
 void SingletonVault::scheduleDestroyInstances() {
+  RequestContext::getStaticContext();
+
   class SingletonVaultDestructor {
    public:
     ~SingletonVaultDestructor() {
index 54eb74b5179f02a67d10d04586785789797feabb..11ff198f7a86d24e5f0cf7432909ca126da5b1c6 100644 (file)
@@ -96,6 +96,7 @@
 #include <folly/Hash.h>
 #include <folly/Memory.h>
 #include <folly/RWSpinLock.h>
+#include <folly/io/async/Request.h>
 
 #include <algorithm>
 #include <vector>
@@ -326,6 +327,7 @@ class SingletonVault {
   // Mark registration is complete; no more singletons can be
   // registered at this point.
   void registrationComplete() {
+    RequestContext::getStaticContext();
     std::atexit([](){ SingletonVault::singleton()->destroyInstances(); });
 
     RWSpinLock::WriteHolder wh(&stateMutex_);