From 703b8ae039c472b5112c5729abc66cac51b8a463 Mon Sep 17 00:00:00 2001 From: yijiem Date: Thu, 1 Feb 2024 13:55:38 -0800 Subject: [PATCH] fix --- src/core/lib/event_engine/forkable.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/core/lib/event_engine/forkable.cc b/src/core/lib/event_engine/forkable.cc index 98e77d8babf..a51f1176506 100644 --- a/src/core/lib/event_engine/forkable.cc +++ b/src/core/lib/event_engine/forkable.cc @@ -43,13 +43,15 @@ bool IsForkEnabled() { void ObjectGroupForkHandler::RegisterForkable( std::shared_ptr forkable, GRPC_UNUSED void (*prepare)(void), GRPC_UNUSED void (*parent)(void), GRPC_UNUSED void (*child)(void)) { - GPR_ASSERT(!is_forking_); - forkables_.emplace_back(forkable); + if (IsForkEnabled()) { + GPR_ASSERT(!is_forking_); + forkables_.emplace_back(forkable); #ifdef GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK - if (!std::exchange(registered_, true)) { - pthread_atfork(prepare, parent, child); - } + if (!std::exchange(registered_, true)) { + pthread_atfork(prepare, parent, child); + } #endif // GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK + } } void ObjectGroupForkHandler::Prefork() {