Skip to content

Commit

Permalink
Fix data race when joining the task runner (#1493)
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hulk authored Jun 13, 2023
1 parent ad704f5 commit e89af52
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/common/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Status TaskRunner::Join() {

for (auto &thread : threads_) {
if (auto s = util::ThreadJoin(thread); !s) {
return s.Prefixed("Task thread operation failed");
LOG(WARNING) << "Failed to join thread: " << s.Msg();
continue;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ void Server::Join() {
worker->Join();
}

if (auto s = task_runner_.Join(); !s) {
LOG(WARNING) << s.Msg();
}
if (auto s = util::ThreadJoin(cron_thread_); !s) {
LOG(WARNING) << "Cron thread operation failed: " << s.Msg();
}
if (auto s = util::ThreadJoin(compaction_checker_thread_); !s) {
LOG(WARNING) << "Compaction checker thread operation failed: " << s.Msg();
}
if (auto s = task_runner_.Join(); !s) {
LOG(WARNING) << s.Msg();
}
}

Status Server::AddMaster(const std::string &host, uint32_t port, bool force_reconnect) {
Expand Down
2 changes: 2 additions & 0 deletions tests/cppunit/task_runner_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,6 @@ TEST(TaskRunner, PublishAfterStart) {
std::this_thread::sleep_for(0.1s);

ASSERT_EQ(counter, 20);
tr.Cancel();
_ = tr.Join();
}

0 comments on commit e89af52

Please sign in to comment.