{"record":{"id":"1bfda39d8d7c2368","repo":"nautechsystems/nautilus_trader","slug":"ocm-state-lock-poisoned","errorCode":null,"errorMessage":"OCM state lock poisoned","messagePattern":"OCM state lock poisoned","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/adapters/betfair/src/execution.rs","lineNumber":2040,"sourceCode":"            self.emitter\n                .emit_order_denied(&order, &OrderDeniedReason::StreamReconciling.to_string());\n            return Ok(());\n        }\n\n        if order.is_closed() {\n            log::warn!(\"Cannot submit closed order {}\", order.client_order_id());\n            return Ok(());\n        }\n\n        let instrument_id = order.instrument_id();\n        let market_id = extract_market_id(&instrument_id)?;\n        let (selection_id, handicap) = extract_selection_id(&instrument_id)?;\n\n        let instruction = create_place_instruction(&order, selection_id, handicap)?;\n        let collision = self\n            .ocm_state\n            .lock()\n            .map_err(|_| anyhow::anyhow!(\"OCM state lock poisoned\"))?\n            .register_submission(order.client_order_id(), order.strategy_id())\n            .err();\n\n        if let Some(customer_order_ref) = collision {\n            let reason = customer_order_ref_collision_reason(&customer_order_ref);\n            log::warn!(\"Denying submit for {}: {reason}\", order.client_order_id(),);\n            self.emitter.emit_order_denied(&order, &reason);\n            return Ok(());\n        }\n\n        let market_version = self.get_market_version(&instrument_id);\n\n        let params = PlaceOrdersParams {\n            market_id,\n            instructions: vec![instruction],\n            customer_ref: Some(order_customer_ref()),\n            market_version,\n            customer_strategy_ref: None,","sourceCodeStart":2022,"sourceCodeEnd":2058,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/d1527c24afdf475115785557f89a55c3e336c51f/crates/adapters/betfair/src/execution.rs#L2022-L2058","documentation":"ocm_state is a std::sync::Mutex<OcmState> shared by the OCM (order change message) reconciliation path; lock() returned a PoisonError, meaning some thread panicked while holding this mutex. From that point every OCM poll (fetch_fill_reports_via_http) fails with this message until the process restarts. The real defect is the earlier panic in the logs, not this error.","triggerScenarios":"Any panic inside a critical section holding ocm_state (fill-report building, customer_order_ref registration in the submit paths) poisons the lock; a subsequent generate_fill_reports call then hits the poisoned lock at execution.rs:3038.","commonSituations":"An upstream panic (decimal parse, unwrap, index) during order reconciliation masks itself as 'lock poisoned' on all later OCM polls; common after an unexpected venue payload triggers a panic in the parsing path.","solutions":["Search logs backwards from this error for the originating panic and its backtrace; fix or report that panic.","Restart the trading node — a poisoned std Mutex never recovers in-process.","If reproducible, capture the CurrentOrderSummary/stream update that triggered the panic and file an issue with the adapter maintainers."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match reports_result {\n    Ok(reports) => { /* process */ }\n    Err(e) if e.to_string().contains(\"lock poisoned\") => {\n        log::error!(\"OCM state poisoned by earlier panic; restart required\");\n        // halt trading safely: cancel open orders if possible, then exit\n        std::process::exit(1);\n    }\n    Err(e) => log::warn!(\"OCM poll failed: {e}\"),\n}","preventionTips":["Treat any panic in the Betfair adapter as critical: run the node with panic backtraces and log capture enabled.","Monitor for the original panic — 'lock poisoned' is always a symptom, not the cause.","Supervise the node process (systemd/k8s) so a poisoned state triggers a clean restart.","Report the triggering payload to maintainers so the panic is fixed."],"tags":["betfair","mutex","poisoned-lock","panic","ocm"],"backgroundTag":"mutex-poisoned","analyzedSha":"d1527c24afdf475115785557f89a55c3e336c51f","analyzedAt":"2026-08-27T04:01:12.327Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}