{"record":{"id":"a572cd02e2592566","repo":"nautechsystems/nautilus_trader","slug":"context","errorCode":null,"errorMessage":"{context}: {}","messagePattern":"\\{context\\}: \\{\\}","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/data/mod.rs","lineNumber":318,"sourceCode":"            &mut self.ws_disconnect_handle,\n            \"WebSocket disconnect\",\n            &mut self.shutdown_errors,\n        )\n        .await;\n\n        if let Err(e) = self.ws_handler_retained.finish().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n\n        self.take_shutdown_result(\"Failed to terminate Lighter tasks\")\n    }\n\n    fn take_shutdown_result(&mut self, context: &str) -> anyhow::Result<()> {\n        if self.shutdown_errors.is_empty() {\n            Ok(())\n        } else {\n            let errors = std::mem::take(&mut self.shutdown_errors);\n            anyhow::bail!(\"{context}: {}\", errors.join(\"; \"))\n        }\n    }\n\n    async fn finish_owned_task(\n        slot: &mut TaskSlot<Result<(), LighterWsError>>,\n        description: &str,\n        errors: &mut Vec<String>,\n    ) {\n        let Some(outcome) = finish_task(slot, DISCONNECT_TIMEOUT, DISCONNECT_TIMEOUT).await else {\n            return;\n        };\n\n        match outcome {\n            TaskJoinOutcome::Completed(Ok(())) | TaskJoinOutcome::Aborted => {}\n            TaskJoinOutcome::Completed(Err(e)) => {\n                errors.push(format!(\"{description} failed: {e}\"));\n            }\n            TaskJoinOutcome::Failed(e) => {","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/data/mod.rs#L300-L336","documentation":"Aggregated shutdown-failure error raised by the Lighter data client. When the client tears down (full shutdown, partial-connect teardown, or disconnect) it collects errors from joining each owned WebSocket/task; if any task failed to finish cleanly, take_shutdown_result joins them with '; ' and bails with the context prefix naming which teardown phase failed. The original per-task error text is embedded in the joined message.","triggerScenarios":"Calling disconnect() or shutdown_tasks() on the Lighter data client, or a connect() that failed partway and triggers teardown_partial_connect, while one or more spawned WebSocket reader/writer/heartbeat tasks returned an error (e.g. closed transport, send on closed channel, task panicked).","commonSituations":"Network drop during disconnect causing WS task join errors; reconnect storms leaving stale tasks; broker/remote closing connections mid-teardown; shutting down while a task is mid-reconnect.","solutions":["Read the joined message after the context prefix to find the underlying per-task error and address it (usually a network/WS issue).","Retry the disconnect/shutdown; transient transport errors during teardown are often non-fatal since the client is stopping anyway.","Check network/proxy stability if teardown errors recur on every disconnect.","If a specific task name appears in the joined errors, look at that task's logs for its root cause; report a bug if teardown consistently fails on a healthy connection."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.disconnect().await {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"Failed to terminate\") => {\n        tracing::warn!(\"teardown errors (client stopping anyway): {e:#}\");\n        // inspect joined per-task causes; retry if transient network issue\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Disconnect on a stable connection rather than mid-reconnect when possible.","Treat teardown errors as advisory when the process is exiting anyway; log the joined causes.","Monitor network stability if this recurs."],"tags":["rust","websocket","shutdown","task-management","adapter"],"backgroundTag":"task-shutdown-failed","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"}