Skip to content

Commit 3d34c31

Browse files
Jaesoo Leefacebook-github-bot
authored andcommitted
NavyThread: drain and destruct ScopedEventBaseThread first
Summary: As discovered in the unit test https://fburl.com/testinfra/87ndzjg8, it seems that the segfault could occur while destructing the worker thread, i.e., NavyThread of RegionManager if there are some tasks are outstanding while accessing the mutex which is another member of NavyThread. This change makes sure the ScopedEventBaseThread is destructed after draining any pending fibers before any other member variables. Reviewed By: therealgymmy Differential Revision: D49707371 fbshipit-source-id: 3fcac297d759b70a061ceaee209bfac70f962b4b
1 parent be1cff2 commit 3d34c31

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cachelib/navy/common/NavyThread.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ class NavyThread {
4141
/**
4242
* Initializes with current EventBaseManager and passed-in thread name.
4343
*/
44-
explicit NavyThread(folly::StringPiece name)
45-
: th_(name), fm_(&folly::fibers::getFiberManager(*th_.getEventBase())) {}
44+
explicit NavyThread(folly::StringPiece name) {
45+
th_ = std::make_unique<folly::ScopedEventBaseThread>(name.str());
46+
fm_ = &folly::fibers::getFiberManager(*th_->getEventBase());
47+
}
4648

47-
~NavyThread() = default;
49+
~NavyThread() { th_.reset(); }
4850

4951
/**
5052
* Add the passed-in task to the FiberManager.
@@ -71,7 +73,7 @@ class NavyThread {
7173
NavyThread& operator=(const NavyThread& other) = delete;
7274

7375
// Actual worker thread running EventBase and FiberManager loop
74-
folly::ScopedEventBaseThread th_;
76+
std::unique_ptr<folly::ScopedEventBaseThread> th_;
7577

7678
// FiberManager which are driven by the thread
7779
folly::fibers::FiberManager* fm_;

0 commit comments

Comments
 (0)