{"record":{"id":"673fa4870f2cc6e9","repo":"nautechsystems/nautilus_trader","slug":"e-failed-to-roll-back-partial-lighter-connectio","errorCode":null,"errorMessage":"{e}; failed to roll back partial Lighter connection: {shutdown_error}","messagePattern":"(.+?); failed to roll back partial Lighter connection: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/execution.rs","lineNumber":4163,"sourceCode":"                ));\n            }\n            log::error!(\"Lighter integrator approval failed; continuing startup: {e:?}\");\n        }\n\n        self.nonce_ready_connection_epoch\n            .store(NONCE_CONNECTION_EPOCH_UNAVAILABLE, Ordering::Release);\n\n        if let Err(e) = self.sync_nonce_from_venue().await {\n            log::debug!(\n                \"Failed to sync Lighter nonce after integrator approval; continuing startup: {e:?}\"\n            );\n        }\n\n        if let Err(e) = self.spawn_ws_consumer().await {\n            self.begin_session_shutdown();\n            return match self.finish_session_shutdown().await {\n                Ok(()) => Err(e),\n                Err(shutdown_error) => Err(anyhow::anyhow!(\n                    \"{e}; failed to roll back partial Lighter connection: {shutdown_error}\"\n                )),\n            };\n        }\n        self.nonce_ready_connection_epoch\n            .store(self.ws_client.connection_epoch(), Ordering::Release);\n\n        if let Err(e) = self.await_account_streams_ready(30.0).await {\n            log::warn!(\"Connect failed after WS started, tearing down: {e}\");\n            self.begin_session_shutdown();\n\n            if let Err(shutdown_error) = self.finish_session_shutdown().await {\n                log::warn!(\"Failed to finish partial Lighter connection: {shutdown_error}\");\n            }\n\n            return Err(e);\n        }\n","sourceCodeStart":4145,"sourceCodeEnd":4181,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/execution.rs#L4145-L4181","documentation":"When spawning the WebSocket consumer during Lighter connection setup fails, the client begins a session shutdown to roll back the partially established connection. If that rollback itself fails, both the original spawn error and the shutdown error are combined into this single anyhow error so no failure context is lost.","triggerScenarios":"spawn_ws_consumer() failed (e.g. WebSocket connect error) AND finish_session_shutdown() also returned an error while tearing down the partially initialized session — typically because pending tasks or the ws client were already in a broken state.","commonSituations":"Network outage during connect where cleanup also hits the dead connection; reconnect storms leaving the task group mid-shutdown; calling connect after a previous incomplete shutdown.","solutions":["Inspect both error halves; the original spawn error is the root cause, the shutdown error is secondary","Fully drop/recreate the client or task group if its state prevents clean shutdown","Ensure the ws endpoint is reachable (network, auth) before reconnecting to avoid the initial spawn failure"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// probe reachability before connect\nTcpStream::connect((host, port)).await?;","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"roll back partial\") => {\n        // rebuild client; original spawn error is root cause\n    }\n    other => other?,\n}","preventionTips":["Check network/endpoint health before connecting","Allow shutdown to complete fully between reconnect attempts","Treat this error as unrecoverable client state and rebuild"],"tags":["rust","lighter","websocket","cleanup","reconnect"],"backgroundTag":"connection-refused","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"}