{"record":{"id":"03362ccd25311e9b","repo":"nautechsystems/nautilus_trader","slug":"cannot-request-aggregated-bars-one-of-the-aggrega","errorCode":null,"errorMessage":"Cannot request aggregated bars: one of the aggregators in `bar_types` is already running","messagePattern":"Cannot request aggregated bars: one of the aggregators in `bar_types` is already running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/engine/mod.rs","lineNumber":1521,"sourceCode":"        target.activation_ns = UnixNanos::default();\n        target.expiration_ns = UnixNanos::default();\n\n        if let Err(e) = self\n            .cache\n            .borrow_mut()\n            .add_instrument(InstrumentAny::FuturesContract(target))\n        {\n            log_error_on_cache_insert(&e);\n        }\n    }\n\n    fn prepare_request_bar_aggregators_from_state(\n        &mut self,\n        request_id: UUID4,\n        state: &RequestBarAggregation,\n    ) -> anyhow::Result<()> {\n        if !self.can_start_request_bar_aggregators(request_id, state) {\n            anyhow::bail!(\n                \"Cannot request aggregated bars: one of the aggregators in `bar_types` is already running\"\n            );\n        }\n\n        self.request_bar_aggregations\n            .insert(request_id, state.clone());\n\n        if let Err(e) = self.init_request_bar_aggregators(request_id, state) {\n            self.cleanup_request_bar_aggregators(&request_id);\n            return Err(e);\n        }\n\n        Ok(())\n    }\n\n    fn dispatch_next_continuous_future_segment(&mut self, request_id: UUID4) -> anyhow::Result<()> {\n        let Some(state) = self.continuous_future_requests.get(&request_id).cloned() else {\n            anyhow::bail!(\"No active continuous future request for {request_id}\");","sourceCodeStart":1503,"sourceCodeEnd":1539,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/engine/mod.rs#L1503-L1539","documentation":"Before starting bar aggregators for a new request, the engine checks can_start_request_bar_aggregators; if any aggregator for one of the requested bar_types is already running for another request, it refuses to avoid duplicate aggregation. This guards against conflicting concurrent bar aggregation for the same bar type.","triggerScenarios":"Calling DataEngine.request_bars (or a second bars request with the same bar_types aggregation) while a previous request's aggregators for those bar_types are still active — e.g. requesting 1-MINUTE bars from 1-SECOND trades while an identical aggregation is already registered.","commonSituations":"Re-issuing a bars request without canceling/deregistering the previous one; two strategies independently requesting the same aggregated bar type from the same source; restarting a backtest segment without cleaning up prior aggregation state.","solutions":["Cancel or let the earlier bar request complete before issuing an identical aggregation request","Reuse the existing bar subscription/request instead of requesting the same bar_types aggregation again","Use a distinct bar_type (different aggregation source or interval) if both requests are genuinely needed","If aggregators are stale, reset/restart the engine or deregister the prior request's aggregation state"],"exampleFix":"// before\nengine.request_bars(bar_req_1min);\nengine.request_bars(bar_req_1min); // duplicate aggregation\n// after\nif !engine.has_bars(bar_req_1min.bar_type()) {\n    engine.request_bars(bar_req_1min);\n} else {\n    // reuse existing subscription\n}","handlingStrategy":"validation","validationCode":"// skip duplicate aggregation requests\nif engine.has_bars(&bar_type) {\n    log::info!(\"aggregation already active for {bar_type}\");\n    return Ok(());\n}\nengine.request_bars(req);","typeGuard":null,"tryCatchPattern":"match engine.request_bars(req) {\n    Err(e) if e.to_string().contains(\"already running\") => {\n        log::warn!(\"reusing existing aggregators for requested bar_types\");\n    }\n    other => other?,\n}","preventionTips":["Check engine.has_bars(bar_type) before requesting the same aggregation","Centralize bar requests so multiple strategies share one aggregation","Cancel prior bar requests before re-issuing in restart/replay flows"],"tags":["rust","data-engine","bar-aggregation","conflicting-state"],"backgroundTag":"conflicting-config-options","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}