Commit da3a4406 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Fix SerialExecutor task destruction order

Summary: [Folly] Fix SerialExecutor task destruction order where tasks are destroyed outside of the request-context scope.

Reviewed By: andriigrynenko

Differential Revision: D15618395

fbshipit-source-id: e2ec8e42137d14f549f92dbc96a904eadcc0a587
parent 436efbfe
......@@ -80,7 +80,8 @@ void SerialExecutor::run() {
try {
folly::RequestContextScopeGuard ctxGuard(std::move(task.ctx));
task.func();
auto func = std::move(task.func);
func();
} catch (std::exception const& ex) {
LOG(ERROR) << "SerialExecutor: func threw unhandled exception "
<< folly::exceptionStr(ex);
......
......@@ -16,6 +16,7 @@
#include <chrono>
#include <folly/ScopeGuard.h>
#include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/executors/InlineExecutor.h>
#include <folly/executors/SerialExecutor.h>
......@@ -62,13 +63,16 @@ void simpleTest(std::shared_ptr<folly::Executor> const& parent) {
SerialExecutorContextData::kCtxKey(),
std::make_unique<SerialExecutorContextData>(i));
folly::RequestContextScopeGuard ctxGuard(ctx);
executor->add([i, &values] {
static auto checkReqCtx = [](auto i) {
EXPECT_EQ(
i,
dynamic_cast<SerialExecutorContextData*>(
folly::RequestContext::get()->getContextData(
SerialExecutorContextData::kCtxKey()))
->getId());
};
executor->add([i, g = folly::makeGuard([i] { checkReqCtx(i); }), &values] {
checkReqCtx(i);
// make this extra vulnerable to concurrent execution
values.push_back(0);
burnMs(10);
......
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