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

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


The following commit(s) were added to refs/heads/unstable by this push:
     new 1d86294bd fix(replication): Fix Seg Fault On Signal When Replication 
is Enabled (#3131)
1d86294bd is described below

commit 1d86294bd5970c09f6c185e9b3564289f4d51cda
Author: Zhixin Wen <[email protected]>
AuthorDate: Tue Aug 19 18:31:46 2025 -0700

    fix(replication): Fix Seg Fault On Signal When Replication is Enabled 
(#3131)
---
 src/common/thread_util.h            | 10 ++++++++++
 utils/kvrocks2redis/redis_writer.cc | 17 +++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/common/thread_util.h b/src/common/thread_util.h
index 67b1d0614..f4c9cc753 100644
--- a/src/common/thread_util.h
+++ b/src/common/thread_util.h
@@ -20,6 +20,8 @@
 
 #pragma once
 
+#include <signal.h>
+
 #include <system_error>
 #include <thread>
 
@@ -34,6 +36,14 @@ template <typename F>
 StatusOr<std::thread> CreateThread(const char *name, F f) {
   try {
     return std::thread([name, f = std::move(f)] {
+      // Block SIGTERM and SIGINT signals in this thread,
+      // the signal should be handled by the main thread or a dedicated thread.
+      sigset_t signal_set;
+      sigemptyset(&signal_set);
+      sigaddset(&signal_set, SIGTERM);
+      sigaddset(&signal_set, SIGINT);
+      pthread_sigmask(SIG_BLOCK, &signal_set, nullptr);
+
       ThreadSetName(name);
       f();
     });
diff --git a/utils/kvrocks2redis/redis_writer.cc 
b/utils/kvrocks2redis/redis_writer.cc
index 932d96ca9..98f75e432 100644
--- a/utils/kvrocks2redis/redis_writer.cc
+++ b/utils/kvrocks2redis/redis_writer.cc
@@ -24,23 +24,20 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include <system_error>
-
 #include "io_util.h"
 #include "server/redis_reply.h"
 #include "thread_util.h"
 
 RedisWriter::RedisWriter(kvrocks2redis::Config *config) : Writer(config) {
-  try {
-    t_ = std::thread([this]() {
-      util::ThreadSetName("redis-writer");
-      this->sync();
-      assert(stop_flag_);
-    });
-  } catch (const std::system_error &e) {
-    error("Failed to create thread: {}", e.what());
+  auto t = util::CreateThread("redis-writer", [this]() {
+    this->sync();
+    assert(stop_flag_);
+  });
+  if (!t.IsOK()) {
+    error("Failed to create thread: {}", t.Msg());
     return;
   }
+  t_ = std::move(*t);
 }
 
 RedisWriter::~RedisWriter() {

Reply via email to