{"record":{"id":"aa28723eab666b20","repo":"nautechsystems/nautilus_trader","slug":"cannot-override-url-arc-has-multiple-references","errorCode":null,"errorMessage":"cannot override URL: Arc has multiple references","messagePattern":"cannot override URL: Arc has multiple references","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/http/client.rs","lineNumber":1055,"sourceCode":"            .filter(|cached_cloid| **cached_cloid == cloid)\n            .count();\n\n        (mapping_count == 1).then_some(cloid)\n    }\n\n    /// Removes the cached CLOID for a client order ID.\n    pub fn remove_client_order_id_cloid(&self, client_order_id: &ClientOrderId) -> Option<Cloid> {\n        self.client_order_id_cloids.lock().remove(client_order_id)\n    }\n\n    /// Overrides the base info URL (for testing with mock servers).\n    ///\n    /// # Panics\n    ///\n    /// Panics if the inner `Arc` has multiple references.\n    pub fn set_base_info_url(&mut self, url: String) {\n        Arc::get_mut(&mut self.inner)\n            .expect(\"cannot override URL: Arc has multiple references\")\n            .set_base_info_url(url);\n    }\n\n    /// Overrides the base exchange URL (for testing with mock servers).\n    ///\n    /// # Panics\n    ///\n    /// Panics if the inner `Arc` has multiple references.\n    pub fn set_base_exchange_url(&mut self, url: String) {\n        Arc::get_mut(&mut self.inner)\n            .expect(\"cannot override URL: Arc has multiple references\")\n            .set_base_exchange_url(url);\n    }\n\n    /// Creates an authenticated client from environment variables for the specified network.\n    ///\n    /// # Errors\n    ///","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/http/client.rs#L1037-L1073","documentation":"The Hyperliquid client stores shared configuration in an `Arc`; `set_base_info_url` uses `Arc::get_mut` to override the URL in place, which only succeeds when the Arc has exactly one reference (strong count 1). The method is intended for test setup before the client is shared. If the inner Arc has been cloned or shared (e.g. across tasks), mutating is impossible and the method panics.","triggerScenarios":"Calling `set_base_info_url` after the client's inner Arc was cloned — e.g. after passing the client (or a clone) to spawned tasks, other components, or holding multiple handles; also calling it concurrently with any other holder of the inner state.","commonSituations":"Test code that shares the client with a websocket client or cache before trying to point it at a mock server; production code calling the setter on a long-lived, already-shared client; reconfiguration attempts at runtime instead of construction time.","solutions":["Call `set_base_info_url` immediately after construction, before any clone or sharing of the client.","For runtime reconfiguration, use the constructor with an explicit URL (`HyperliquidHttpClient::new`) and rebuild/re-share the client instead of mutating.","Wrap the override in a check or use interior mutability (RwLock) in the inner state if runtime mutation is genuinely required.","In tests, build the client with the mock-server URL from the start rather than overriding afterwards."],"exampleFix":"// before\nlet client = HyperliquidHttpClient::default();\nlet shared = client.clone();\nclient.set_base_info_url(mock_url); // panics: Arc has multiple refs\n// after\nlet mut client = HyperliquidHttpClient::default();\nclient.set_base_info_url(mock_url); // before any clone/sharing\nlet shared = client.clone();","handlingStrategy":"validation","validationCode":"if Arc::strong_count(&client.inner) != 1 {\n    // URL already shared; rebuild the client with new() instead of overriding\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Override URLs only immediately after construction, before any clone","Build test clients with the mock-server URL via new() directly","Rebuild the client for runtime reconfiguration instead of mutating shared state"],"tags":["rust","panic","arc","mutability","testing"],"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"}