From 06396d7aeccdd7c3e7310c5acf4e687c12109052 Mon Sep 17 00:00:00 2001 From: erhant Date: Tue, 23 Jun 2026 16:45:03 +0300 Subject: [PATCH] fix: expore `stop_indexer` for outside-restarts --- src/lez_indexer_module_impl.cpp | 23 +++++++++++++++++------ src/lez_indexer_module_impl.h | 6 ++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lez_indexer_module_impl.cpp b/src/lez_indexer_module_impl.cpp index 78ff5c9..2b312ba 100644 --- a/src/lez_indexer_module_impl.cpp +++ b/src/lez_indexer_module_impl.cpp @@ -21,12 +21,8 @@ namespace { } // namespace LezIndexerModuleImpl::~LezIndexerModuleImpl() { - if (indexer_service_ffi) { - OperationStatus operation_result = stop_indexer(handle(indexer_service_ffi)); - if (is_error(&operation_result)) { - warn("destructor", "indexer FFI error on stop"); - } - indexer_service_ffi = nullptr; + if (stop_indexer() != 0) { + warn("destructor", "indexer FFI error on stop"); } } @@ -50,6 +46,21 @@ int64_t LezIndexerModuleImpl::start_indexer(const std::string& config_path) { return 0; } +int64_t LezIndexerModuleImpl::stop_indexer() { + if (!indexer_service_ffi) { + return 0; // not running + } + // stop_indexer frees the handle; null ours before returning so a later start + // (or the destructor) doesn't double-free or operate on a dead pointer. + OperationStatus operation_result = ::stop_indexer(handle(indexer_service_ffi)); + indexer_service_ffi = nullptr; + if (is_error(&operation_result)) { + warn("stop_indexer", "indexer FFI error on stop"); + return static_cast(operation_result); + } + return 0; +} + void LezIndexerModuleImpl::init_logger(const std::string& level) { ::init_logger(level.c_str()); } diff --git a/src/lez_indexer_module_impl.h b/src/lez_indexer_module_impl.h index 662de39..1a2df06 100644 --- a/src/lez_indexer_module_impl.h +++ b/src/lez_indexer_module_impl.h @@ -35,6 +35,12 @@ public: /// as scalar wire types; a plain `int` return is treated as a JSON payload. int64_t start_indexer(const std::string& config_path); + /// Stop ingestion and release the FFI handle. No-op (returns 0) when the + /// indexer isn't running. Pair with start_indexer to apply a new config: + /// stop, then start (start_indexer stays idempotent and won't restart on its + /// own). Returns 0 on success, else the FFI OperationStatus code. + int64_t stop_indexer(); + /// Account by 32-byte hex id. The returned JSON omits the id; callers inject /// the queried id themselves. std::string getAccount(const std::string& account_id);