{"record":{"id":"50f963314961f78f","repo":"nautechsystems/nautilus_trader","slug":"disconnect-timeout-while-disconnecting-clients","errorCode":null,"errorMessage":"disconnect timeout while disconnecting clients","messagePattern":"disconnect timeout while disconnecting clients","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/live/src/node/mod.rs","lineNumber":2363,"sourceCode":"            log::error!(\"Error stopping plug-in controllers: {e}\");\n        }\n        self.kernel.stop_trader();\n        let delay = self.kernel.delay_post_stop();\n        log::info!(\"Awaiting residual events ({delay:?})...\");\n\n        self.shutdown_deadline = Some(dst::time::Instant::now() + delay);\n        self.handle.set_shutting_down();\n    }\n\n    async fn finalize_stop(&mut self) -> anyhow::Result<()> {\n        self.close_external_ingress();\n\n        let timeout = self.config.timeout_disconnection;\n        let deadline = dst::time::Instant::now() + timeout;\n        let disconnect_result =\n            match dst::time::timeout(timeout, self.kernel.disconnect_clients()).await {\n                Ok(result) => result,\n                Err(_) => Err(anyhow::anyhow!(\n                    \"disconnect timeout while disconnecting clients\"\n                )),\n            };\n\n        if let Err(ref e) = disconnect_result {\n            log::error!(\"Error disconnecting clients: {e}\");\n        }\n\n        let readiness_result = self.await_engines_disconnected(deadline).await;\n        let kernel_result = self.kernel.finalize_stop().await;\n\n        self.handle.set_stopped();\n\n        let mut errors = Vec::new();\n        if let Err(e) = disconnect_result {\n            errors.push(e.to_string());\n        }\n","sourceCodeStart":2345,"sourceCodeEnd":2381,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/node/mod.rs#L2345-L2381","documentation":"finalize_stop disconnects all kernel clients under config.timeout_disconnection. If disconnect_clients() does not finish within that window, the timeout elapses, this error is constructed, and it is logged as \"Error disconnecting clients\" while the stop proceeds. It indicates a client hung during disconnect, but the node still continues its shutdown sequence.","triggerScenarios":"In finalize_stop (called from stop and all abort paths), dst::time::timeout(timeout_disconnection, disconnect_clients()) returns Err (mod.rs:2358-2368) because one or more clients' disconnect futures hang.","commonSituations":"Broken WebSocket connections whose adapters wait on a send/flush that can never complete; venue APIs unresponsive during disconnect; very small timeout_disconnection values; network partitions at shutdown time.","solutions":["Increase timeout_disconnection in the live config to accommodate slow client teardown.","Check adapter logs for a specific client hanging in disconnect and fix or update that adapter.","Force-close stuck network connections (firewall reset, process restart) if a half-open socket is the cause.","This is logged but non-fatal; confirm all clients actually reconnected cleanly on the next startup."],"exampleFix":"// before\ntimeout_disconnection: Duration::from_secs(2)\n// after\ntimeout_disconnection: Duration::from_secs(30)","handlingStrategy":"fallback","validationCode":"// Ensure disconnect budget is realistic for adapter teardown\nassert!(config.timeout_disconnection >= Duration::from_secs(10));","typeGuard":null,"tryCatchPattern":"// The node logs and continues, but callers of stop() should still check:\nnode.stop().await; // timeout is logged internally as \"Error disconnecting clients\"\n// optionally verify state afterwards:\nif node.is_running() { /* force cleanup or restart */ }","preventionTips":["Set timeout_disconnection generously (e.g. 30s)","Keep adapters updated to avoid hangs in disconnect/flush paths","Monitor for half-open sockets after shutdown","Treat the logged error as a prompt to investigate, not a fatal failure"],"tags":["timeout","shutdown","network","disconnect"],"backgroundTag":"request-timeout","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"}