Commit d99292ef authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook Github Bot

Fix default VirtualEventBase access race exposed by TSAN

Reviewed By: iahs

Differential Revision: D19873296

fbshipit-source-id: f92785feb33be09bdef4c047532b4bd3dd42972e
parent e195d5c3
......@@ -498,8 +498,10 @@ ssize_t EventBase::loopKeepAliveCount() {
void EventBase::applyLoopKeepAlive() {
auto keepAliveCount = loopKeepAliveCount();
// Make sure default VirtualEventBase won't hold EventBase::loop() forever.
if (virtualEventBase_ && virtualEventBase_->keepAliveCount() == 1) {
--keepAliveCount;
if (auto virtualEventBase = tryGetVirtualEventBase()) {
if (virtualEventBase->keepAliveCount() == 1) {
--keepAliveCount;
}
}
if (loopKeepAliveActive_ && keepAliveCount == 0) {
......@@ -844,6 +846,13 @@ VirtualEventBase& EventBase::getVirtualEventBase() {
return *virtualEventBase_;
}
VirtualEventBase* EventBase::tryGetVirtualEventBase() {
if (folly::test_once(virtualEventBaseInitFlag_)) {
return virtualEventBase_.get();
}
return nullptr;
}
EventBase* EventBase::getEventBase() {
return this;
}
......
......@@ -828,6 +828,8 @@ class EventBase : public TimeoutManager,
}
private:
folly::VirtualEventBase* tryGetVirtualEventBase();
void applyLoopKeepAlive();
ssize_t loopKeepAliveCount();
......
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