Appearance
Graceful Shutdown
The framework supports graceful shutdown, ensuring all connections, timers, and state are cleaned up before the process exits.
app.stop() — Stopping the App
Triggers a graceful shutdown of all services.
cpp
app.stop();Shutdown Sequence
| Step | What Happens |
|---|---|
| 1 | Timers cancelled — All internal timers (metrics, dashboard, gossip, Raft) are stopped. |
| 2 | Task registry stops — No new scheduled tasks are created. Pending tasks are cancelled. |
| 3 | Listeners close — TCP and HTTP listeners stop accepting new connections. |
| 4 | Connections drain — All active peer-to-peer and client connections are closed gracefully via their strands. |
| 5 | State cleanup — Registries are cleared, pools are stopped, WAL is flushed. |
Signal Handling
The framework automatically registers handlers for SIGINT and SIGTERM that call app.stop(). You do not need to handle signals manually.
wait_for_registries_clear(timeout) — Verifying Clean Shutdown
After stopping, wait for all registries to be fully cleared.
cpp
using namespace framework;
bool all_clear = app.get_state()->wait_for_registries_clear(std::chrono::seconds(30));
if (!all_clear) {
LOG_WARN_SVC(config, "Some connections did not close within the timeout");
}| Param | Description |
|---|---|
timeout | Maximum time to wait for registries to clear. |
| Returns | true if all registries cleared, false if timeout was reached. |
is_stopping() — Checking Shutdown State
cpp
if (app.get_state()->is_stopping()) {
// The app is in the process of shutting down
}