{"record":{"id":"0f9c0d8bf2d36d60","repo":"nautechsystems/nautilus_trader","slug":"cannot-submit-order-list-order-list-id-cache-is","errorCode":null,"errorMessage":"Cannot submit order list {order_list.id}: cache is currently borrowed","messagePattern":"Cannot submit order list (.+?): cache is currently borrowed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":265,"sourceCode":"        let strategy_id = registered_strategy_id(core)?;\n        let ts_init = core.clock_mut().timestamp_ns();\n\n        // TODO: Replace with fluent builder API for order list construction\n        let order_list = if orders.first().is_some_and(|o| o.order_list_id().is_some()) {\n            OrderList::from_orders(&orders, ts_init)\n        } else {\n            core.order_factory().create_list(&mut orders, ts_init)\n        };\n\n        if let Err(e) = order_list.validate() {\n            log::error!(\"OrderList denied: {e}\");\n            anyhow::bail!(\"OrderList denied: {e}\");\n        }\n\n        {\n            let cache_rc = core.cache_rc();\n            let mut cache = cache_rc.try_borrow_mut().map_err(|_| {\n                anyhow::anyhow!(\n                    \"Cannot submit order list {}: cache is currently borrowed\",\n                    order_list.id\n                )\n            })?;\n\n            if cache.order_list_exists(&order_list.id) {\n                anyhow::bail!(\"OrderList denied: duplicate {}\", order_list.id);\n            }\n\n            for order in &orders {\n                if cache.order_exists(&order.client_order_id()) {\n                    anyhow::bail!(\n                        \"Order in list denied: duplicate {}\",\n                        order.client_order_id()\n                    );\n                }\n            }\n","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L247-L283","documentation":"Before adding the order list to the Cache, `submit_order_list` attempts a mutable borrow of the shared Cache via `try_borrow_mut`. If the Cache is already borrowed on the same thread the submission fails with `Cannot submit order list {order_list.id}: cache is currently borrowed`. This is a single-threaded re-entrancy/borrow conflict, not a lock contention issue.","triggerScenarios":"Calling `submit_order_list` while a mutable cache borrow is outstanding — e.g. from inside a callback while the engine dispatch holds the cache, or while user code holds a cache handle obtained earlier.","commonSituations":"Submitting orders from within `on_event`/handlers nested inside a cache-borrowing code path; retaining a cache borrow guard across the submit call; custom adapters or exec algorithms re-entering submission during cache iteration.","solutions":["Defer the submission out of the nested context (e.g. queue the order list and submit from `on_start` or a timer/event after dispatch completes).","Drop any retained cache borrow guards before calling `submit_order_list`.","Avoid submitting orders while iterating cache collections in the same call stack.","If triggered by an exec algorithm, restructure so child orders are submitted from a fresh event-cycle callback."],"exampleFix":"// before\nfor order in self.cache.orders_open(...):  # holds cache borrow\n    self.submit_order_list(build_list(order))  # re-entrant borrow -> error\n// after\npending = [build_list(o) for o in list(self.cache.orders_open(...))]\nfor ol in pending:\n    self.submit_order_list(ol)  # submitted after iteration completes","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    self.submit_order_list(order_list)\nexcept Exception as e:\n    if 'cache is currently borrowed' in str(e):\n        self._deferred_lists.append(order_list)  # submit later from a timer/event\n    else:\n        raise","preventionTips":["Do not submit orders while iterating cache collections","Drop cache borrow guards before submission calls","Queue submissions during dispatch and flush from a later callback","Avoid deeply nested handler stacks that re-enter submission paths"],"tags":["cache","borrow","concurrency","order-submission"],"backgroundTag":"internal-invariant-violation","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"}