{"record":{"id":"91a2a39ea5489e7f","repo":"nautechsystems/nautilus_trader","slug":"derive-execution-ws-event-receiver-not-initialized","errorCode":null,"errorMessage":"Derive execution WS event receiver not initialized","messagePattern":"Derive execution WS event receiver not initialized","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/execution.rs","lineNumber":628,"sourceCode":"        }\n        let cancellation_token = self.cancellation_token.clone();\n        let ws_shutdown = self.ws_client.shutdown_handle();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                cancellation_token.cancel();\n                ws_shutdown.begin_shutdown();\n            });\n\n        self.ensure_instruments_initialized()\n            .await\n            .context(\"failed to initialize Derive instruments\")?;\n\n        self.ws_client\n            .connect()\n            .await\n            .context(\"failed to connect Derive WebSocket\")?;\n        let Some(rx) = self.ws_client.take_event_receiver() else {\n            let e = anyhow::anyhow!(\"Derive execution WS event receiver not initialized\");\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(e.context(format!(\n                    \"Derive execution startup teardown failed: {teardown_error}\"\n                )));\n            }\n            return Err(e);\n        };\n\n        let subaccount_id = self.credential.subaccount_id();\n        let channels = vec![\n            DeriveWsChannel::orders(subaccount_id),\n            DeriveWsChannel::private_trades(subaccount_id),\n            DeriveWsChannel::balances(subaccount_id),\n        ];\n\n        if let Err(e) = self.ws_client.subscribe_channels(channels).await {\n            log::warn!(\"Derive private WS subscriptions failed: {e}; tearing down\");\n            if let Err(teardown_error) = self.teardown_partial_connect().await {","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/execution.rs#L610-L646","documentation":"After establishing the WebSocket connection, connect expects the WS client to hand over its event receiver via take_event_receiver(). If none is available (receiver already taken or never created), the client tears down and raises this error. It indicates an internal initialization failure of the Derive execution WebSocket client.","triggerScenarios":"Calling connect twice on the same WS client (the receiver is taken only once, Option consumed); a WS client constructed in a way that never created the event channel; connecting after a partial failure that already consumed the receiver.","commonSituations":"Reusing a single execution client instance across reconnects where the receiver wasn't recreated; bespoke wiring of the WS client bypassing the adapter's constructor; internal invariant violation after a failed prior connect.","solutions":["Recreate the Derive execution client (or its WS client) instead of reconnecting on the same instance, so the event receiver is fresh.","If this occurs on a first connect, it is an internal bug — check the adapter version and report/inspect how the WS client was constructed.","Upgrade to a newer version of the derive adapter in case the receiver lifecycle bug was fixed.","Check whether a prior connect consumed take_event_receiver without a subsequent client reset."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match exec_client.connect().await {\n    Err(e) if e.to_string().contains(\"event receiver not initialized\") => {\n        // internal invariant broken — recreate the client and retry once\n        let fresh = DeriveExecutionClient::new(...)?;\n        fresh.connect().await?;\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Never call connect twice on the same WS-backed client (the receiver is take-once)","Construct the client through the adapter's constructor/factory, not by manual WS wiring","Keep the adapter updated; first-connect occurrence usually indicates a bug to report"],"tags":["derive","websocket","internal-invariant","connect","rust"],"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"}