Skip to content

Commit

Permalink
Set the socket attrs in the EVB thread context to avoid a race condit…
Browse files Browse the repository at this point in the history
…ion reported by TSAN

Summary: Set the socket attrs in the EVB thread context to avoid a race condition reported by TSAN

Reviewed By: yfeldblum

Differential Revision: D23216182

fbshipit-source-id: 219854ef1844c1acd909019a5897fc6922406921
  • Loading branch information
dmm-fb authored and facebook-github-bot committed Aug 20, 2020
1 parent d07f378 commit 0580653
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions thrift/lib/cpp2/server/ThriftServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,16 +330,19 @@ void ThriftServer::setup() {
// zeroCopyEnableFunc_ is valid
bool useZeroCopy = !!zeroCopyEnableFunc_;
for (auto& socket : getSockets()) {
socket->setShutdownSocketSet(wShutdownSocketSet_);
socket->setAcceptRateAdjustSpeed(acceptRateAdjustSpeed_);
socket->setZeroCopy(useZeroCopy);

try {
socket->setTosReflect(tosReflect_);
} catch (std::exception const& ex) {
LOG(ERROR) << "Got exception setting up TOS reflect: "
<< folly::exceptionStr(ex);
}
auto* evb = socket->getEventBase();
evb->runImmediatelyOrRunInEventBaseThreadAndWait([&] {
socket->setShutdownSocketSet(wShutdownSocketSet_);
socket->setAcceptRateAdjustSpeed(acceptRateAdjustSpeed_);
socket->setZeroCopy(useZeroCopy);

try {
socket->setTosReflect(tosReflect_);
} catch (std::exception const& ex) {
LOG(ERROR) << "Got exception setting up TOS reflect: "
<< folly::exceptionStr(ex);
}
});
}

// Notify handler of the preServe event
Expand Down

0 comments on commit 0580653

Please sign in to comment.