diff --git a/lez/indexer/service/src/lib.rs b/lez/indexer/service/src/lib.rs index 945c75be..aa142b38 100644 --- a/lez/indexer/service/src/lib.rs +++ b/lez/indexer/service/src/lib.rs @@ -88,7 +88,7 @@ pub async fn run_server( #[cfg(not(feature = "mock-responses"))] let handle = { - let service = service::IndexerService::new(config, storage_dir, shutdown) + let service = service::IndexerService::new(config, storage_dir, shutdown.child_token()) .await .context("Failed to initialize indexer service")?; server.start(service.into_rpc()) diff --git a/lez/indexer/service/src/service.rs b/lez/indexer/service/src/service.rs index 3ef6a598..09759362 100644 --- a/lez/indexer/service/src/service.rs +++ b/lez/indexer/service/src/service.rs @@ -175,6 +175,10 @@ impl indexer_service_rpc::RpcServer for IndexerService { struct SubscriptionService { parts: ArcSwap, indexer: IndexerCore, + /// Cancellation token that is used to signal the subscription service to shut down. + /// + /// NOTE: This will auto-cancel on `Drop`, so if your token is shared with other parts + /// use [`CancellationToken::child_token()`] instead. shutdown: CancellationToken, } @@ -292,6 +296,7 @@ impl SubscriptionService { impl Drop for SubscriptionService { fn drop(&mut self) { + self.shutdown.cancel(); self.parts.load().handle.abort(); } } diff --git a/lez/sequencer/service/src/main.rs b/lez/sequencer/service/src/main.rs index e78ad502..8b577bb8 100644 --- a/lez/sequencer/service/src/main.rs +++ b/lez/sequencer/service/src/main.rs @@ -24,6 +24,8 @@ async fn main() -> Result<()> { let Args { config_path, port } = Args::parse(); + // TODO: handle this cancellation token more gracefully within Sequencer service + // similar to how we do in Indexer let cancellation_token = listen_for_shutdown_signal(); let config = sequencer_service::SequencerConfig::from_path(&config_path)?;