Skip to content

Commit a1b8e6c

Browse files
authored
BugFix: Fix the problem of occasional core dump in the Fiber TimerWorker when the program exits (#148)
1 parent 7b33450 commit a1b8e6c

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

trpc/common/config/client_conf_parser.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ struct convert<trpc::ServiceProxyConfig> {
103103
if (node["recv_buffer_size"]) proxy_config.recv_buffer_size = node["recv_buffer_size"].as<uint32_t>();
104104
if (node["send_queue_capacity"]) proxy_config.send_queue_capacity = node["send_queue_capacity"].as<uint32_t>();
105105
if (node["send_queue_timeout"]) proxy_config.send_queue_timeout = node["send_queue_timeout"].as<uint32_t>();
106-
if (node["endpoint_hash_bucket_size"]) proxy_config.endpoint_hash_bucket_size = node["endpoint_hash_bucket_size"].as<uint32_t>();
106+
if (node["endpoint_hash_bucket_size"]) {
107+
proxy_config.endpoint_hash_bucket_size = node["endpoint_hash_bucket_size"].as<uint32_t>();
108+
}
107109
if (node["threadmodel_type"]) proxy_config.threadmodel_type = node["threadmodel_type"].as<std::string>();
108-
if (node["threadmodel_instance_name"]) proxy_config.threadmodel_instance_name = node["threadmodel_instance_name"].as<std::string>();
110+
if (node["threadmodel_instance_name"]) {
111+
proxy_config.threadmodel_instance_name = node["threadmodel_instance_name"].as<std::string>();
112+
}
109113
if (node["selector_name"]) proxy_config.selector_name = node["selector_name"].as<std::string>();
110114
if (node["namespace"]) proxy_config.namespace_ = node["namespace"].as<std::string>();
111115
if (node["load_balance_name"]) proxy_config.load_balance_name = node["load_balance_name"].as<std::string>();

trpc/runtime/threadmodel/fiber/detail/assembly.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern "C" {
4848

4949
// FIXME: TSan support does not work yet.
5050
#ifdef TRPC_INTERNAL_USE_TSAN
51+
#ifndef TRPC_INTERNAL_EXCLUDE_TSAN_INTERFACE
5152
extern "C" {
5253
[[gnu::weak]] void* __tsan_get_current_fiber(void);
5354
[[gnu::weak]] void* __tsan_create_fiber(unsigned);
@@ -78,6 +79,7 @@ const unsigned __tsan_mutex_recursive_unlock = 1 << 7;
7879
[[gnu::weak]] void __tsan_acquire(void*);
7980
[[gnu::weak]] void __tsan_release(void*);
8081
}
82+
#endif
8183

8284
#define TRPC_INTERNAL_TSAN_MUTEX_CREATE(...) __tsan_mutex_create(__VA_ARGS__)
8385
#define TRPC_INTERNAL_TSAN_MUTEX_DESTROY(...) __tsan_mutex_destroy(__VA_ARGS__)

trpc/runtime/threadmodel/fiber/fiber_thread_model.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,27 @@ void FiberThreadModel::Start() noexcept {
129129
}
130130

131131
void FiberThreadModel::Terminate() noexcept {
132+
// Exit the timer worker first due to it uses the tls variable of the FiberWorker thread.
132133
for (auto&& e : scheduling_groups_) {
133134
for (auto&& ee : e) {
134135
ee->timer_worker->Stop();
135-
ee->scheduling_group->Stop();
136136
}
137137
}
138138

139139
for (auto&& e : scheduling_groups_) {
140140
for (auto&& ee : e) {
141141
ee->timer_worker->Join();
142+
}
143+
}
144+
145+
for (auto&& e : scheduling_groups_) {
146+
for (auto&& ee : e) {
147+
ee->scheduling_group->Stop();
148+
}
149+
}
150+
151+
for (auto&& e : scheduling_groups_) {
152+
for (auto&& ee : e) {
142153
for (auto&& eee : ee->fiber_workers) {
143154
eee->Join();
144155
}

0 commit comments

Comments
 (0)