Skip to content

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

StepWhat Happens
1Timers cancelled — All internal timers (metrics, dashboard, gossip, Raft) are stopped.
2Task registry stops — No new scheduled tasks are created. Pending tasks are cancelled.
3Listeners close — TCP and HTTP listeners stop accepting new connections.
4Connections drain — All active peer-to-peer and client connections are closed gracefully via their strands.
5State 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");
}
ParamDescription
timeoutMaximum time to wait for registries to clear.
Returnstrue 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
}