diff options
author | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-04 16:12:47 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@broadpark.no> | 2021-02-04 16:26:18 +0100 |
commit | efafbd02b274d94fee3f20af785b239392c0f69f (patch) | |
tree | e2a053717a7edf75d19e697de554542ba6608ebb /searchcore/src/apps/proton/proton.cpp | |
parent | 21dcc03fb48657b38d490d3708dc9a473c1735e6 (diff) |
Call std::_Exit(0) if SIGINT or SIGTERM is received while loading
data structures, replaying transaction log or performing startup reprocessing.
Diffstat (limited to 'searchcore/src/apps/proton/proton.cpp')
-rw-r--r-- | searchcore/src/apps/proton/proton.cpp | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/searchcore/src/apps/proton/proton.cpp b/searchcore/src/apps/proton/proton.cpp index f01f3486a79..d02cfcb8dff 100644 --- a/searchcore/src/apps/proton/proton.cpp +++ b/searchcore/src/apps/proton/proton.cpp @@ -136,6 +136,45 @@ ProtonServiceLayerProcess::getGeneration() const return std::min(slGen, protonGen); } +namespace { + +class ExitOnSignal { + std::atomic<bool> _stop; + std::thread _thread; + +public: + ExitOnSignal(); + ~ExitOnSignal(); + void operator()(); +}; + +ExitOnSignal::ExitOnSignal() + : _stop(false), + _thread() +{ + _thread = std::thread(std::ref(*this)); +} + +ExitOnSignal::~ExitOnSignal() +{ + _stop.store(true, std::memory_order_relaxed); + _thread.join(); +} + +void +ExitOnSignal::operator()() +{ + while (!_stop.load(std::memory_order_relaxed)) { + if (SIG::INT.check() || SIG::TERM.check()) { + EV_STOPPING("proton", "unclean shutdown after interrupted init"); + std::_Exit(0); + } + std::this_thread::sleep_for(100ms); + } +} + +} + int App::Main() { @@ -160,7 +199,10 @@ App::Main() } else { proton.getMetricManager().init(params.identity, proton.getThreadPool()); } - proton.init(configSnapshot); + { + ExitOnSignal exit_on_signal; + proton.init(configSnapshot); + } configSnapshot.reset(); std::unique_ptr<ProtonServiceLayerProcess> spiProton; if ( ! params.serviceidentity.empty()) { |