You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kvrocks.apache.org by hu...@apache.org on 2023/06/13 08:21:17 UTC

[incubator-kvrocks] branch unstable updated: Fix data race when joining the task runner (#1493)

This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new e89af528 Fix data race when joining the task runner (#1493)
e89af528 is described below

commit e89af5289d5c3d12c47628394c72f0d67e652800
Author: hulk <hu...@gmail.com>
AuthorDate: Tue Jun 13 16:21:10 2023 +0800

    Fix data race when joining the task runner (#1493)
---
 src/common/task_runner.cc         | 3 ++-
 src/server/server.cc              | 6 +++---
 tests/cppunit/task_runner_test.cc | 2 ++
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/common/task_runner.cc b/src/common/task_runner.cc
index 318d5800..810a66c5 100644
--- a/src/common/task_runner.cc
+++ b/src/common/task_runner.cc
@@ -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;
     }
   }
 
diff --git a/src/server/server.cc b/src/server/server.cc
index 6be0aae7..a9a117d9 100644
--- a/src/server/server.cc
+++ b/src/server/server.cc
@@ -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) {
diff --git a/tests/cppunit/task_runner_test.cc b/tests/cppunit/task_runner_test.cc
index 8407adbf..2d4ab308 100644
--- a/tests/cppunit/task_runner_test.cc
+++ b/tests/cppunit/task_runner_test.cc
@@ -103,4 +103,6 @@ TEST(TaskRunner, PublishAfterStart) {
   std::this_thread::sleep_for(0.1s);
 
   ASSERT_EQ(counter, 20);
+  tr.Cancel();
+  _ = tr.Join();
 }