From e51bba3df7f2a2f98489995899ffaf433e8c66a6 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Mon, 18 Jul 2022 12:11:31 -0400 Subject: [PATCH 1/2] Allow disabling the guard dog Which Envoy Mobile should never enable, because terminating the Envoy process would mean terminating the host iOS or Android app. Signed-off-by: JP Simard --- bazel/BUILD | 21 +++++++++++++++++++++ bazel/envoy_build_system.bzl | 2 ++ bazel/envoy_internal.bzl | 3 ++- bazel/envoy_select.bzl | 7 +++++++ source/server/BUILD | 4 ++-- source/server/server.cc | 8 ++++++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index 31bb1ea4016b..8c79e3c9b630 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -301,6 +301,27 @@ config_setting( values = {"define": "deprecated_features=disabled"}, ) +bool_flag( + name = "guarddog", + build_setting_default = True, + visibility = ["//visibility:private"], +) + +config_setting( + name = "disable_guarddog_setting", + flag_values = { + ":guarddog": "False", + }, + visibility = ["//visibility:private"], +) + +selects.config_setting_group( + name = "disable_guarddog", + match_any = [ + ":disable_guarddog_setting", + ], +) + bool_flag( name = "http3", build_setting_default = True, diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index f87903151df8..e48b0c5f3a3d 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -21,6 +21,7 @@ load( _envoy_select_admin_html = "envoy_select_admin_html", _envoy_select_admin_no_html = "envoy_select_admin_no_html", _envoy_select_boringssl = "envoy_select_boringssl", + _envoy_select_enable_guarddog = "envoy_select_enable_guarddog", _envoy_select_enable_http3 = "envoy_select_enable_http3", _envoy_select_google_grpc = "envoy_select_google_grpc", _envoy_select_hot_restart = "envoy_select_hot_restart", @@ -212,6 +213,7 @@ envoy_select_admin_html = _envoy_select_admin_html envoy_select_admin_no_html = _envoy_select_admin_no_html envoy_select_boringssl = _envoy_select_boringssl envoy_select_google_grpc = _envoy_select_google_grpc +envoy_select_enable_guarddog = _envoy_select_enable_guarddog envoy_select_enable_http3 = _envoy_select_enable_http3 envoy_select_hot_restart = _envoy_select_hot_restart envoy_select_wasm_cpp_tests = _envoy_select_wasm_cpp_tests diff --git a/bazel/envoy_internal.bzl b/bazel/envoy_internal.bzl index 76bce7f05a71..9c45e1260991 100644 --- a/bazel/envoy_internal.bzl +++ b/bazel/envoy_internal.bzl @@ -1,6 +1,6 @@ # DO NOT LOAD THIS FILE. Targets from this file should be considered private # and not used outside of the @envoy//bazel package. -load(":envoy_select.bzl", "envoy_select_admin_html", "envoy_select_enable_http3", "envoy_select_google_grpc", "envoy_select_hot_restart") +load(":envoy_select.bzl", "envoy_select_admin_html", "envoy_select_enable_guarddog", "envoy_select_enable_http3", "envoy_select_google_grpc", "envoy_select_hot_restart") # Compute the final copts based on various options. def envoy_copts(repository, test = False): @@ -124,6 +124,7 @@ def envoy_copts(repository, test = False): }) + envoy_select_hot_restart(["-DENVOY_HOT_RESTART"], repository) + \ envoy_select_admin_html(["-DENVOY_ADMIN_HTML"], repository) + \ envoy_select_enable_http3(["-DENVOY_ENABLE_QUIC"], repository) + \ + envoy_select_enable_guarddog(["-DENVOY_ENABLE_GUARDDOG"], repository) + \ _envoy_select_perf_annotation(["-DENVOY_PERF_ANNOTATION"]) + \ _envoy_select_perfetto(["-DENVOY_PERFETTO"]) + \ envoy_select_google_grpc(["-DENVOY_GOOGLE_GRPC"], repository) + \ diff --git a/bazel/envoy_select.bzl b/bazel/envoy_select.bzl index 50c34b8388b7..adccced4ddfb 100644 --- a/bazel/envoy_select.bzl +++ b/bazel/envoy_select.bzl @@ -45,6 +45,13 @@ def envoy_select_enable_http3(xs, repository = ""): "//conditions:default": xs, }) +# Selects the given values if the guard dog is enabled in the current build. +def envoy_select_enable_guarddog(xs, repository = ""): + return select({ + repository + "//bazel:disable_guarddog": [], + "//conditions:default": xs, + }) + # Selects the given values if hot restart is enabled in the current build. def envoy_select_hot_restart(xs, repository = ""): return select({ diff --git a/source/server/BUILD b/source/server/BUILD index a1d7ac686fa0..4d89d79a8449 100644 --- a/source/server/BUILD +++ b/source/server/BUILD @@ -3,6 +3,7 @@ load( "envoy_cc_library", "envoy_package", "envoy_proto_library", + "envoy_select_enable_guarddog", "envoy_select_enable_http3", "envoy_select_hot_restart", ) @@ -577,7 +578,6 @@ envoy_cc_library( ":active_raw_udp_listener_config", ":configuration_lib", ":connection_handler_lib", - ":guarddog_lib", ":listener_hooks_lib", ":listener_manager_lib", ":ssl_context_manager_lib", @@ -633,7 +633,7 @@ envoy_cc_library( "//source/server/admin:admin_lib", "@envoy_api//envoy/admin/v3:pkg_cc_proto", "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto", - ], + ] + envoy_select_enable_guarddog([":guarddog_lib"]), ) envoy_cc_library( diff --git a/source/server/server.cc b/source/server/server.cc index 9cd42ec3a581..86a462be7b8d 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -55,7 +55,9 @@ #include "source/server/admin/utils.h" #include "source/server/configuration_impl.h" #include "source/server/connection_handler_impl.h" +#ifdef ENVOY_ENABLE_GUARDDOG #include "source/server/guarddog_impl.h" +#endif #include "source/server/listener_hooks.h" #include "source/server/ssl_context_manager.h" @@ -731,12 +733,14 @@ void InstanceImpl::initialize(Network::Address::InstanceConstSharedPtr local_add bootstrap_extension->onServerInitialized(); } +#ifdef ENVOY_ENABLE_GUARDDOG // GuardDog (deadlock detection) object and thread setup before workers are // started and before our own run() loop runs. main_thread_guard_dog_ = std::make_unique( stats_store_, config_.mainThreadWatchdogConfig(), *api_, "main_thread"); worker_guard_dog_ = std::make_unique( stats_store_, config_.workerWatchdogConfig(), *api_, "workers"); +#endif } void InstanceImpl::onClusterManagerPrimaryInitializationComplete() { @@ -902,13 +906,17 @@ void InstanceImpl::run() { // Run the main dispatch loop waiting to exit. ENVOY_LOG(info, "starting main dispatch loop"); +#ifdef ENVOY_ENABLE_GUARDDOG auto watchdog = main_thread_guard_dog_->createWatchDog(api_->threadFactory().currentThreadId(), "main_thread", *dispatcher_); +#endif dispatcher_->post([this] { notifyCallbacksForStage(Stage::Startup); }); dispatcher_->run(Event::Dispatcher::RunType::Block); ENVOY_LOG(info, "main dispatch loop exited"); +#ifdef ENVOY_ENABLE_GUARDDOG main_thread_guard_dog_->stopWatching(watchdog); watchdog.reset(); +#endif terminate(); } From c35dad0c8a59939f7b27a4275e288f2f90fa7876 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Thu, 29 Sep 2022 16:07:59 -0400 Subject: [PATCH 2/2] Fix import formatting Signed-off-by: JP Simard --- source/server/server.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/server/server.cc b/source/server/server.cc index 86a462be7b8d..d7e45ac52277 100644 --- a/source/server/server.cc +++ b/source/server/server.cc @@ -55,11 +55,12 @@ #include "source/server/admin/utils.h" #include "source/server/configuration_impl.h" #include "source/server/connection_handler_impl.h" +#include "source/server/listener_hooks.h" +#include "source/server/ssl_context_manager.h" + #ifdef ENVOY_ENABLE_GUARDDOG #include "source/server/guarddog_impl.h" #endif -#include "source/server/listener_hooks.h" -#include "source/server/ssl_context_manager.h" namespace Envoy { namespace Server {