feat: Graceful shutdown with old web server (#2786)

- Stop accepting connections during graceful shutdown in the old web server
- Stop all the services before Clio exits
- Move cache saving into stop callback
This commit is contained in:
Sergey Kuznetsov
2025-11-19 15:40:33 +00:00
committed by GitHub
parent 56f074e6ee
commit b62cfe949f
17 changed files with 414 additions and 47 deletions

View File

@@ -19,6 +19,8 @@
#include "util/StopHelper.hpp"
#include "util/Spawn.hpp"
#include <boost/asio/spawn.hpp>
#include <boost/asio/steady_timer.hpp>
@@ -37,7 +39,7 @@ void
StopHelper::asyncWaitForStop(boost::asio::yield_context yield)
{
boost::asio::steady_timer timer{yield.get_executor(), std::chrono::steady_clock::duration::max()};
onStopReady_.connect([&timer]() { timer.cancel(); });
onStopReady_.connect([&]() { util::spawn(yield, [&timer](auto&&) { timer.cancel(); }); });
boost::system::error_code error;
if (!*stopped_)
timer.async_wait(yield[error]);

View File

@@ -36,6 +36,16 @@ class StopHelper {
std::unique_ptr<std::atomic_bool> stopped_ = std::make_unique<std::atomic_bool>(false);
public:
StopHelper() = default;
~StopHelper() = default;
StopHelper(StopHelper&&) = delete;
StopHelper&
operator=(StopHelper&&) = delete;
StopHelper(StopHelper const&) = delete;
StopHelper&
operator=(StopHelper const&) = delete;
/**
* @brief Notify that the class is ready to stop.
*/