{"record":{"id":"642299390c828e92","repo":"zed-industries/zed","slug":"aborting-reconnect-because-not-in-state-that-allo","errorCode":null,"errorMessage":"aborting reconnect, because not in state that allows reconnecting: {state}","messagePattern":"aborting reconnect, because not in state that allows reconnecting: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/remote/src/remote_client.rs","lineNumber":601,"sourceCode":"            drop(delegate);\n        })\n    }\n\n    fn reconnect(&mut self, cx: &mut Context<Self>) -> Result<()> {\n        let can_reconnect = self\n            .state\n            .as_ref()\n            .map(|state| state.can_reconnect())\n            .unwrap_or(false);\n        if !can_reconnect {\n            let state = if let Some(state) = self.state.as_ref() {\n                state.to_string()\n            } else {\n                \"no state set\".to_string()\n            };\n            log::info!(\n                \"aborting reconnect, because not in state that allows reconnecting: {state}\"\n            );\n            anyhow::bail!(\n                \"aborting reconnect, because not in state that allows reconnecting: {state}\"\n            );\n        }\n\n        let state = self.state.take().unwrap();\n        let (attempts, remote_connection, delegate) = match state {\n            State::Connected {\n                remote_connection,\n                delegate,\n                multiplex_task,\n                heartbeat_task,\n            }\n            | State::HeartbeatMissed {\n                remote_connection,\n                delegate,\n                multiplex_task,\n                heartbeat_task,","sourceCodeStart":583,"sourceCodeEnd":619,"githubUrl":"https://github.com/zed-industries/zed/blob/5a9b9558db01a6b906cec2fb70a797affdc58cdd/crates/remote/src/remote_client.rs#L583-L619","documentation":"RemoteClient's reconnect flow only runs from states that still own a remote connection. State::can_reconnect() (crates/remote/src/remote_client.rs:228) is true only for Connected, HeartbeatMissed and ReconnectFailed; calling reconnect from Connecting, Reconnecting, ReconnectExhausted, ServerNotRunning - or with no state set at all - logs and bails with the offending state name (crates/remote/src/remote_client.rs:601).","triggerScenarios":"Invoking RemoteClient::reconnect while the client is Connecting or already Reconnecting (a double reconnect), after reconnect attempts were exhausted (ReconnectExhausted), after the server was detected as not running, or before any state was established.","commonSituations":"Multiple components reacting to the same disconnect and racing to reconnect; custom retry loops stacked on top of the client's built-in reconnection; reconnecting a client that was never shut down cleanly.","solutions":["Let the client's own reconnection state machine drive reconnects instead of calling reconnect() manually from every error handler","Before forcing a reconnect, wait until the client leaves Connecting/Reconnecting (check its connection-state API)","After ReconnectExhausted or ServerNotRunning, start a brand-new connection instead of reconnecting the dead one"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Only reconnect when the client can actually retry:\n// allowed states are Connected, HeartbeatMissed, ReconnectFailed.\n// Externally, gate on the client's connection-state API instead of calling reconnect() blindly.\nif remote_client.connection_state() == ConnectionState::Disconnected {\n    remote_client.reconnect(cx);\n}","typeGuard":null,"tryCatchPattern":"match remote_client.reconnect(cx) {\n    Err(e) if e.to_string().contains(\"not in state that allows reconnecting\") => {\n        // benign guard: another reconnect is already in flight - ignore\n    }\n    other => other?,\n}","preventionTips":["Centralize reconnect triggers in one place; never fan out reconnect() from every error handler","After ReconnectExhausted or ServerNotRunning, create a new connection rather than reconnecting the old client"],"tags":["remote","reconnect","state-machine","ssh"],"backgroundTag":"invalid-state-transition","analyzedSha":"5a9b9558db01a6b906cec2fb70a797affdc58cdd","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}