backport patches to fix issues such as grpc hangs. Signed-off-by: chenjingwen <lhchenjw@gmail.com>
49 lines
1.7 KiB
Diff
49 lines
1.7 KiB
Diff
From b6705fe2d5b4aefdc0db16ae6ec9d75b69e8f421 Mon Sep 17 00:00:00 2001
|
|
From: hurricane618 <hurricane618@hotmail.com>
|
|
Date: Wed, 6 Dec 2023 22:12:27 +0800
|
|
Subject: [PATCH] add lock limit publish API
|
|
|
|
call publish too quick, so add lock to limit it.
|
|
|
|
Signed-off-by: hurricane618 <hurricane618@hotmail.com>
|
|
---
|
|
observer_agent/service/main.cpp | 8 ++++++--
|
|
1 file changed, 6 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/observer_agent/service/main.cpp b/observer_agent/service/main.cpp
|
|
index bd01690..8c24345 100644
|
|
--- a/observer_agent/service/main.cpp
|
|
+++ b/observer_agent/service/main.cpp
|
|
@@ -80,6 +80,10 @@ static void sig_handler(int sig)
|
|
}
|
|
static bool debug = false;
|
|
|
|
+static std::string server_address("unix:///var/run/secDetector.sock");
|
|
+PubSubClient client;
|
|
+std::mutex pub_mutex;
|
|
+
|
|
static void push_log(int type, const std::string &content)
|
|
{
|
|
if ((topic_mask & type) == 0)
|
|
@@ -92,8 +96,7 @@ static void push_log(int type, const std::string &content)
|
|
}
|
|
|
|
// push to grpc
|
|
- std::string server_address("unix:///var/run/secDetector.sock");
|
|
- PubSubClient client(grpc::CreateChannel(server_address, grpc::InsecureChannelCredentials()));
|
|
+ std::lock_guard<std::mutex> lock(pub_mutex);
|
|
client.Publish(type, content);
|
|
}
|
|
|
|
@@ -179,6 +182,7 @@ int main(int argc, char *argv[])
|
|
std::thread thread_grpc = std::thread(RunServer);
|
|
std::thread thread_ebpf_process = std::thread(StartProcesseBPFProg, ebpf_cb, ringbuf_size_bytes, topic_mask);
|
|
std::thread thread_ebpf_file = std::thread(StartFileBPFProg, ebpf_cb, ringbuf_size_bytes, topic_mask);
|
|
+ client.init(grpc::CreateChannel(server_address, grpc::InsecureChannelCredentials()));
|
|
|
|
while (exiting == 0)
|
|
{
|
|
--
|
|
2.33.0
|
|
|