Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix race condition in scheduler reset #179

Merged
merged 2 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/scheduler/Executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ void Executor::finish()

// Shut down thread pools and wait
for (int i = 0; i < threadPoolThreads.size(); i++) {
if (threadPoolThreads.at(i) == nullptr) {
continue;
}

// Send a kill message
SPDLOG_TRACE("Executor {} killing thread pool {}", id, i);
threadTaskQueues[i].enqueue(
ExecutorTask(POOL_SHUTDOWN, nullptr, nullptr, false, false));

// If already killed, move to the next thread
if (threadPoolThreads.at(i) == nullptr) {
continue;
}

// Await the thread
if (threadPoolThreads.at(i)->joinable()) {
threadPoolThreads.at(i)->join();
Expand Down
28 changes: 28 additions & 0 deletions tests/test/scheduler/test_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,34 @@ TEST_CASE_METHOD(TestExecutorFixture,
REQUIRE(restoreCount == 0);
}

TEST_CASE_METHOD(TestExecutorFixture,
"Test executing function repeatedly and flushing",
"[executor]")
{
std::shared_ptr<BatchExecuteRequest> req =
faabric::util::batchExecFactory("dummy", "simple", 1);
uint32_t msgId = req->messages().at(0).id();
csegarragonz marked this conversation as resolved.
Show resolved Hide resolved
std::vector<std::string> actualHosts;

int numRepeats = 20;
for (int i = 0; i < numRepeats; i++) {
std::vector<std::string> actualHosts =
executeWithTestExecutor(req, false);
csegarragonz marked this conversation as resolved.
Show resolved Hide resolved
faabric::Message result =
sch.getFunctionResult(msgId, SHORT_TEST_TIMEOUT_MS);
std::string expected =
fmt::format("Simple function {} executed", msgId);
REQUIRE(result.outputdata() == expected);

// We sleep for the same timeout threads have, to force a race condition
// between the scheduler's flush and the thread's own cleanup timeout
SLEEP_MS(conf.boundTimeout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could end up being quite a long sleep depending on the default config, and it's multiplied by 20, so it would be good to set this to something very short at the start of this test (e.g. 100ms).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks


// Flush
sch.flushLocally();
}
}

TEST_CASE_METHOD(TestExecutorFixture,
"Test executing chained functions",
"[executor]")
Expand Down