{"record":{"id":"65e5ece1e6a234ba","repo":"nautechsystems/nautilus_trader","slug":"command-receiver-already-taken-65e5ec","errorCode":null,"errorMessage":"Command receiver already taken","messagePattern":"Command receiver already taken","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/live.rs","lineNumber":269,"sourceCode":"    ) -> anyhow::Result<(\n        DatabentoFeedHandler,\n        tokio::sync::mpsc::UnboundedReceiver<DatabentoMessage>,\n    )> {\n        if self.is_closed {\n            anyhow::bail!(\"Client already closed\");\n        }\n\n        if self.is_running {\n            anyhow::bail!(\"Client already running\");\n        }\n\n        log::debug!(\"Starting client\");\n\n        let (msg_tx, msg_rx) = tokio::sync::mpsc::unbounded_channel::<DatabentoMessage>();\n        let cmd_rx = self\n            .cmd_rx\n            .take()\n            .ok_or_else(|| anyhow::anyhow!(\"Command receiver already taken\"))?;\n\n        let feed_handler = DatabentoFeedHandler::new(\n            self.credential.clone(),\n            self.dataset.clone(),\n            cmd_rx,\n            msg_tx,\n            self.publisher_venue_map.clone(),\n            self.symbol_venue_map.clone(),\n            self.use_exchange_as_venue,\n            self.bars_timestamp_on_close,\n            self.reconnect_timeout_mins,\n        );\n\n        self.send_command(HandlerCommand::Start)?;\n        self.is_running = true;\n\n        Ok((feed_handler, msg_rx))\n    }","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/live.rs#L251-L287","documentation":"`DatabentoLiveClient::start` takes the command receiver (`cmd_rx`) out of an `Option` that is consumed on first start; calling `start` a second time finds `None` and raises this error. It enforces the one-shot lifecycle of the client's internal command channel — a client instance cannot be started twice.","triggerScenarios":"Calling `start` (or `py_start`) twice on the same live client instance; restarting a client after a session ended without constructing a fresh client; calling start after `stop` or after a previous run consumed the receiver.","commonSituations":"Restart logic in a long-running process reusing the old client object; exception handlers that retry by calling `start` again instead of rebuilding the client; Python wrappers inadvertently invoking start twice (e.g. both framework and user code).","solutions":["Create a new `DatabentoLiveClient` instance instead of restarting the consumed one","Track client state and only call `start` once per instance","On failure/reconnect, replace the client (rebuild via constructor) rather than re-calling start","Check whether a previous `start`/`stop` already consumed the receiver before calling start"],"exampleFix":"// before\nif client_failed {\n    client.start().await?; // panics with \"Command receiver already taken\"\n}\n\n// after\nif client_failed {\n    client = DatabentoLiveClient::new(/* same config */)?;\n    client.start().await?;\n}","handlingStrategy":"type-guard","validationCode":"// before start\nif client.is_running() {\n    anyhow::bail!(\"client already started\");\n}","typeGuard":"fn can_start(client: &DatabentoLiveClient) -> bool {\n    !client.is_started() // track a started flag in your wrapper\n}","tryCatchPattern":"match client.start().await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Command receiver already taken\") => {\n        log::warn!(\"client already started; rebuilding instance\");\n        client = DatabentoLiveClient::new(/* config */)?;\n        client.start().await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Treat client instances as single-use: start once, rebuild for restarts","Never retry failures by re-calling start on the same instance","Encapsulate lifecycle in a supervisor that owns construction and start"],"tags":["rust","databento","live-streaming","lifecycle","invalid-state"],"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-14T05:17:10.506Z"}