{"record":{"id":"1e4f7ccf8fd2770b","repo":"nautechsystems/nautilus_trader","slug":"cannot-stop-bar-aggregator-no-aggregator-to-stop","errorCode":null,"errorMessage":"Cannot stop bar aggregator: no aggregator to stop for {bar_type}","messagePattern":"Cannot stop bar aggregator: no aggregator to stop for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/data/src/engine/mod.rs","lineNumber":5142,"sourceCode":"                UUID4::new(),\n                cmd.ts_init,\n                Some(cmd.command_id),\n                cmd.params.clone(),\n            );\n            self.execute(DataCommand::Unsubscribe(UnsubscribeCommand::Quotes(\n                unsubscribe,\n            )));\n        }\n    }\n\n    fn stop_bar_aggregator(\n        &mut self,\n        bar_type: BarType,\n        request_id: Option<UUID4>,\n    ) -> anyhow::Result<()> {\n        let key = bar_aggregator_key(bar_type, request_id);\n        let aggregator = self.bar_aggregators.shift_remove(&key).ok_or_else(|| {\n            anyhow::anyhow!(\"Cannot stop bar aggregator: no aggregator to stop for {bar_type}\")\n        })?;\n\n        aggregator.borrow_mut().stop();\n\n        // Unsubscribe any registered message handlers\n        if let Some(subs) = self.bar_aggregator_handlers.remove(&key) {\n            for sub in subs {\n                match sub {\n                    BarAggregatorSubscription::Bar { topic, handler } => {\n                        msgbus::unsubscribe_bars(topic.into(), &handler);\n                    }\n                    BarAggregatorSubscription::Trade { topic, handler } => {\n                        msgbus::unsubscribe_trades(topic.into(), &handler);\n                    }\n                    BarAggregatorSubscription::Quote { topic, handler } => {\n                        msgbus::unsubscribe_quotes(topic.into(), &handler);\n                    }\n                }","sourceCodeStart":5124,"sourceCodeEnd":5160,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L5124-L5160","documentation":"stop_bar_aggregator removes the aggregator from the bar_aggregators map and stops it. If no aggregator is registered for the bar type (and request ID key), removal is impossible and the engine returns this error — the caller asked to stop aggregation that was never started or was already stopped.","triggerScenarios":"Calling unsubscribe_bars/stop_bar_aggregator for a BarType that was never subscribed, double-stopping the same bar type, or passing a request_id different from the one used at subscription time.","commonSituations":"Duplicate teardown in shutdown code; unsubscribing bars after the engine was reset; idempotent cleanup scripts assuming stop is a no-op; request_id mismatch making the key lookup miss.","solutions":["Only call stop_bar_aggregator for bar types previously started; track subscribed bar types in the caller and skip unknown ones.","Make teardown idempotent by checking subscription state (or catching this error and ignoring it) before stopping.","Pass the exact same request_id (or None) used when the aggregation was started.","If the aggregator should exist, check for a prior stop or cache/engine reset earlier in the run."],"exampleFix":"// before\nengine.stop_bar_aggregator(bar_type, request_id)?;\n// after\nif engine.is_subscribed_bars(&bar_type) {\n    engine.stop_bar_aggregator(bar_type, request_id)?;\n}","handlingStrategy":"try-catch","validationCode":"if engine.is_subscribed_bars(&bar_type) {\n    engine.stop_bar_aggregator(bar_type, request_id)?;\n}","typeGuard":null,"tryCatchPattern":"match engine.stop_bar_aggregator(bar_type, request_id) {\n    Err(e) if e.to_string().contains(\"no aggregator to stop\") => { /* already stopped: ignore */ }\n    other => other?,\n}","preventionTips":["Make shutdown/teardown idempotent.","Track active bar subscriptions and only stop those.","Reuse the exact request_id from subscription time.","Don't assume stop is safe on never-started bar types."],"tags":["rust","data-engine","bar-aggregation","idempotency"],"backgroundTag":"resource-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}