diff --git a/main.cc b/main.cc index 33cd206691..b81beb2dfd 100644 --- a/main.cc +++ b/main.cc @@ -1810,6 +1810,18 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl utils::get_local_injector().inject("stop_after_starting_migration_manager", [] { std::raise(SIGSTOP); }); + // Audit must be constructed before the maintenance socket so + // that on shutdown (reverse destruction order) the audit service + // outlives the maintenance socket and in-flight queries can + // still reach audit::inspect() safely. + checkpoint(stop_signal, "starting audit service"); + audit::audit::start_audit(*cfg, token_metadata, qp, mm).handle_exception([&] (auto&& e) { + startlog.error("audit start failed: {}", e); + }).get(); + auto audit_stop = defer([] { + audit::audit::stop_audit().get(); + }); + // XXX: stop_raft has to happen before query_processor and migration_manager // is stopped, since some groups keep using the query // processor until are stopped inside stop_raft. @@ -2357,14 +2369,6 @@ To start the scylla server proper, simply invoke as: scylla server (or just scyl startlog.info("Verifying that all of the tablet keyspaces use rack list replication factors"); db.local().check_rack_list_everywhere(cfg->enforce_rack_list()); - checkpoint(stop_signal, "starting audit service"); - audit::audit::start_audit(*cfg, token_metadata, qp, mm).handle_exception([&] (auto&& e) { - startlog.error("audit start failed: {}", e); - }).get(); - auto audit_stop = defer([] { - audit::audit::stop_audit().get(); - }); - // The table-based audit backend needs Raft (via join_cluster) // to create its keyspace and table. checkpoint(stop_signal, "starting audit storage");