{"record":{"id":"19df7e4a828f95ea","repo":"nautechsystems/nautilus_trader","slug":"websocket-message-receiver-not-available","errorCode":null,"errorMessage":"WebSocket message receiver not available","messagePattern":"WebSocket message receiver not available","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/lifecycle.rs","lineNumber":289,"sourceCode":"            .await\n            .context(\"failed to connect user WebSocket\")?;\n\n        if let Err(e) = self\n            .ws_client\n            .subscribe_user()\n            .await\n            .context(\"failed to subscribe to user channel\")\n        {\n            if let Err(shutdown_error) = self.ws_client.disconnect().await {\n                return Err(e.context(format!(\n                    \"Polymarket WebSocket startup rollback failed: {shutdown_error}\"\n                )));\n            }\n            return Err(e);\n        }\n\n        let Some(mut rx) = self.ws_client.take_message_receiver() else {\n            let receiver_error = anyhow::anyhow!(\"WebSocket message receiver not available\");\n            if let Err(shutdown_error) = self.ws_client.disconnect().await {\n                return Err(receiver_error.context(format!(\n                    \"Polymarket WebSocket startup rollback failed: {shutdown_error}\"\n                )));\n            }\n            return Err(receiver_error);\n        };\n\n        let emitter = self.emitter.clone();\n        let token_instruments = self.shared_token_instruments.clone();\n        let account_id = self.core.account_id;\n        let http_client = self.http_client.clone();\n        let clock = self.clock;\n        let signature_type = self.config.signature_type;\n        let stopping = self.stopping.clone();\n        let user_address = self\n            .secrets\n            .funder","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/lifecycle.rs#L271-L307","documentation":"`start_ws_stream` connects the Polymarket WebSocket client then calls `take_message_receiver()` to obtain the mpsc receiver for incoming messages. If the client cannot produce a receiver (connection not fully established, already taken, or client in a bad state), it returns this error. If the rollback `disconnect()` also fails, the disconnect failure is attached as context.","triggerScenarios":"Calling connect_client when the WS handshake completed at the transport level but the client exposes no message receiver — e.g. the receiver was already taken by a prior connection attempt, or take_message_receiver is only valid exactly once per connection.","commonSituations":"Double-connecting an execution client without tearing down the previous session; a partially failed previous connect left the ws_client in an inconsistent state; connecting the same client from two code paths concurrently.","solutions":["Ensure teardown_partial_connect/teardown completes before reconnecting so a fresh ws_client/receiver is available","Check that connect_client is not invoked twice on the same client instance concurrently","Inspect the 'startup rollback failed' context to see if disconnect also errored, indicating a deeper client-state problem","Recreate/rebuild the execution client if its WS state is irrecoverably inconsistent"],"exampleFix":"// before: reconnect without teardown\nadapter.connect().await?; // receiver already taken\n// after: tear down previous session first\nadapter.teardown_partial_connect().await;\nadapter.connect().await?;","handlingStrategy":"try-catch","validationCode":"// ensure no prior session holds the receiver\nif adapter.is_connected() {\n    adapter.teardown_partial_connect().await;\n}","typeGuard":null,"tryCatchPattern":"match adapter.connect().await {\n    Err(e) if e.to_string().contains(\"receiver not available\") => {\n        adapter.teardown_partial_connect().await;\n        adapter.connect().await?; // retry once on clean state\n    }\n    other => other?,\n}","preventionTips":["Never double-connect the same execution client","Always tear down the previous session before reconnecting","Serialize connect calls behind a mutex/guard"],"tags":["rust","websocket","connection","state-error"],"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"}