Commit f8e888a0 authored by Dave Watson's avatar Dave Watson Committed by Facebook Github Bot

Summary:

Fix requestcontext destruction before globals are destroyed.
Bad stacktrace P59804825

Reviewed By: yfeldblum

Differential Revision: D8797823

fbshipit-source-id: a9cbff159e5a0ab2577cb7412817be5d554aa32f
parent acd11b42
...@@ -21,10 +21,26 @@ ...@@ -21,10 +21,26 @@
#include <folly/MapUtil.h> #include <folly/MapUtil.h>
#include <folly/SingletonThreadLocal.h> #include <folly/SingletonThreadLocal.h>
#include <folly/synchronization/CallOnce.h>
#include <folly/synchronization/Hazptr.h> #include <folly/synchronization/Hazptr.h>
namespace folly { namespace folly {
namespace {
/*
* Some requests may not be deleted until long after main when the
* default hazptr_domain destructs. This may cause destruction
* ordering issues. Instead, cleanup as soon as possible after main
* using atexit.
*/
folly::once_flag atexitflag;
void cleanup(void) {
atexit([]() { hazptr_cleanup(); });
}
} // namespace
struct RequestContext::State : hazptr_obj_base<State> { struct RequestContext::State : hazptr_obj_base<State> {
std::map<std::string, std::shared_ptr<RequestData>> requestData_; std::map<std::string, std::shared_ptr<RequestData>> requestData_;
std::set<RequestData*> callbackData_; std::set<RequestData*> callbackData_;
...@@ -82,6 +98,7 @@ bool RequestContext::doSetContextData( ...@@ -82,6 +98,7 @@ bool RequestContext::doSetContextData(
if (p) { if (p) {
p->retire(); p->retire();
folly::call_once(atexitflag, cleanup);
} }
return true; return true;
...@@ -184,6 +201,7 @@ void RequestContext::clearContextData(const std::string& val) { ...@@ -184,6 +201,7 @@ void RequestContext::clearContextData(const std::string& val) {
if (p) { if (p) {
p->retire(); p->retire();
folly::call_once(atexitflag, cleanup);
} }
} }
......
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