-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: use custom main common to disable listening for termination sig…
…nals (#835) Description: Disabling signal handling in the Server::Options makes it so that the server's event dispatcher does not listen for termination signals such as SIGTERM, SIGINT, etc. Previous crashes in iOS were experienced due to out-of-band event loop exit as described in #831. Ignoring termination signals makes it more likely that the event loop will only exit due to Engine destruction. This PR introduces Envoy::MobileMainCommon, as this is the canonical way to customize how main runs, and options setup per #3424. The new Envoy::MobileMainCommon also does away with other logic in Envoy::MainCommon that does not apply to Envoy Mobile. Risk Level: med - low-level change in termination handling Testing: unit test to assert option is correctly set. End to end test with iOS and Android devices to ensure clean exit when the app using envoy mobile exits (and thus destructs the engine). Moreover, there is no event loop exit any longer when the simulator app receives a SIGTERM, i.e., the event dispatcher is no longer listening to SIGTERM and exiting due to them. Potentially fixes #831. Will need to verify with wider client release. Signed-off-by: Jose Nino jnino@lyft.com Signed-off-by: JP Simard <jp@jpsim.com>
- Loading branch information
Showing
7 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "library/common/envoy_mobile_main_common.h" | ||
|
||
#include "common/runtime/runtime_impl.h" | ||
|
||
namespace Envoy { | ||
|
||
MobileMainCommon::MobileMainCommon(int argc, const char* const* argv) | ||
: options_(argc, argv, &MainCommon::hotRestartVersion, spdlog::level::info), | ||
base_(options_, real_time_system_, default_listener_hooks_, prod_component_factory_, | ||
std::make_unique<Runtime::RandomGeneratorImpl>(), platform_impl_.threadFactory(), | ||
platform_impl_.fileSystem(), nullptr) { | ||
// Disabling signal handling in the options makes it so that the server's event dispatcher _does | ||
// not_ listen for termination signals such as SIGTERM, SIGINT, etc | ||
// (https://github.com/envoyproxy/envoy/blob/048f4231310fbbead0cbe03d43ffb4307fff0517/source/server/server.cc#L519). | ||
// Previous crashes in iOS were experienced due to early event loop exit as described in | ||
// https://github.com/lyft/envoy-mobile/issues/831. Ignoring termination signals makes it more | ||
// likely that the event loop will only exit due to Engine destruction | ||
// https://github.com/lyft/envoy-mobile/blob/a72a51e64543882ea05fba3c76178b5784d39cdc/library/common/engine.cc#L105. | ||
options_.setSignalHandling(false); | ||
} | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include "envoy/event/timer.h" | ||
#include "envoy/server/instance.h" | ||
|
||
#include "common/event/real_time_system.h" | ||
|
||
#include "exe/main_common.h" | ||
#include "exe/platform_impl.h" | ||
|
||
#include "server/listener_hooks.h" | ||
#include "server/options_impl.h" | ||
|
||
namespace Envoy { | ||
|
||
/** | ||
* This class is used instead of Envoy::MainCommon to customize logic for the Envoy Mobile setting. | ||
* It largely leverages Envoy::MainCommonBase. | ||
*/ | ||
class MobileMainCommon { | ||
public: | ||
MobileMainCommon(int argc, const char* const* argv); | ||
bool run() { return base_.run(); } | ||
|
||
/** | ||
* @return a pointer to the server instance, or nullptr if initialized into | ||
* validation mode. | ||
*/ | ||
Server::Instance* server() { return base_.server(); } | ||
|
||
private: | ||
PlatformImpl platform_impl_; | ||
Envoy::OptionsImpl options_; | ||
Event::RealTimeSystem real_time_system_; // NO_CHECK_FORMAT(real_time) | ||
DefaultListenerHooks default_listener_hooks_; | ||
ProdComponentFactory prod_component_factory_; | ||
MainCommonBase base_; | ||
}; | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
load("@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", "envoy_package") | ||
|
||
envoy_package() | ||
|
||
envoy_cc_test( | ||
name = "envoy_mobile_main_common_test", | ||
srcs = ["envoy_mobile_main_common_test.cc"], | ||
repository = "@envoy", | ||
deps = [ | ||
"//library/common:envoy_mobile_main_common_lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "gtest/gtest.h" | ||
#include "library/common/envoy_mobile_main_common.h" | ||
|
||
namespace Envoy { | ||
|
||
TEST(MobileMainCommonTest, SignalHandlingFalse) { | ||
std::vector<const char*> envoy_argv{"envoy", "--config-yaml", "{}", nullptr}; | ||
MobileMainCommon main_common{3, &envoy_argv[0]}; | ||
ASSERT_FALSE(main_common.server()->options().signalHandlingEnabled()); | ||
} | ||
|
||
} // namespace Envoy |