{"record":{"id":"ef98fbac831ff40b","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-ib-data-farm-monitor","errorCode":null,"errorMessage":"failed to register IB data farm monitor","messagePattern":"failed to register IB data farm monitor","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/data/core.rs","lineNumber":752,"sourceCode":"        let cancellation_token = self.cancellation_token.child_token();\n        let clock = self.clock;\n\n        if let Err(e) = self.session_tasks.spawn(async move {\n            if let Err(e) =\n                monitor_data_farm_notices(client, data_farm_state, clock, cancellation_token).await\n            {\n                tracing::warn!(\"IB data farm notice monitor stopped: {e:?}\");\n            }\n        }) {\n            self.session_tasks.begin_shutdown();\n            self.command_tasks.begin_shutdown();\n            self.ib_client = None;\n\n            if let Err(teardown_error) = self.finish_tasks().await {\n                return Err(anyhow::Error::new(e)\n                    .context(format!(\"IB data startup teardown failed: {teardown_error}\")));\n            }\n            return Err(anyhow::Error::new(e).context(\"failed to register IB data farm monitor\"));\n        }\n        self.is_connected.store(true, Ordering::Relaxed);\n\n        let instrument_count = self.instrument_provider.count();\n        if instrument_count > 0 {\n            tracing::debug!(\n                \"Data client connected with {} instruments in provider cache\",\n                instrument_count\n            );\n\n            for instrument in self.instrument_provider.get_all() {\n                if let Err(e) = self.data_sender.send(DataEvent::Instrument(instrument)) {\n                    tracing::warn!(\"Failed to publish startup-loaded instrument: {e}\");\n                    break;\n                }\n            }\n        }\n","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/data/core.rs#L734-L770","documentation":"InteractiveBrokersDataClient::connect reaches the point of spawning the IB data farm notice monitor task; if the spawn into session_tasks fails, the client rolls back (shuts down task groups, clears ib_client) and returns the original spawn error wrapped as 'failed to register IB data farm monitor'.","triggerScenarios":"connect() to IB Gateway/TWS succeeds, then session_tasks.spawn() of monitor_data_farm_notices returns Err — typically because the task group is already shut down or the async runtime cannot spawn new tasks.","commonSituations":"Double-connect on the same client instance, connecting after a prior disconnect, or running inside a runtime that is shutting down; also seen when a previous connect failure left the task group poisoned.","solutions":["Read the wrapped source error (use {e:#} in logs) to see why the spawn failed.","Do not call connect() twice on one client; instantiate a new client for a fresh connection.","Ensure disconnect() completes before reconnecting the same client.","Confirm the tokio runtime is active (not in shutdown) for the duration of connect()."],"exampleFix":"// before\nclient.connect().await?; // ... later\nclient.connect().await?; // Err: failed to register IB data farm monitor\n// after\nclient.disconnect().await?; client.connect().await?; // or build a new client","handlingStrategy":"try-catch","validationCode":"// ensure task groups are not already shut down before connect\nif client.is_connected() { return Ok(()); }","typeGuard":"fn can_connect(client: &IBDataClient) -> bool { !client.is_connected() }","tryCatchPattern":"match client.connect().await {\n    Err(e) if format!(\"{e:#}\").contains(\"failed to register IB data farm monitor\") => {\n        // task group poisoned; create a new client instead of retrying on this one\n    }\n    r => r?,\n}","preventionTips":["One connect() per client lifecycle; rebuild on failure","Complete disconnect() before any re-connect","Verify runtime health before spawning clients","Log with {e:#} to expose the wrapped spawn error"],"tags":["rust","interactive-brokers","task-spawn","async"],"backgroundTag":"invalid-state-transition","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"}