{"record":{"id":"785739ea70ec56bd","repo":"nautechsystems/nautilus_trader","slug":"session-ended-by-gateway","errorCode":null,"errorMessage":"Session ended by gateway","messagePattern":"Session ended by gateway","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/live.rs","lineNumber":766,"sourceCode":"                        log::debug!(\"Closed inner client\");\n                        return Ok(false);\n                    }\n                    None => {\n                        log::debug!(\"Command channel disconnected\");\n                        return Ok(false);\n                    }\n                },\n                result = client.next_record() => result,\n            };\n\n            let record = match record_opt {\n                Ok(Some(record)) => record,\n                Ok(None) => {\n                    if session_start.elapsed() >= self.success_threshold {\n                        log::debug!(\"Session ended after successful run\");\n                        return Ok(true);\n                    }\n                    anyhow::bail!(\"Session ended by gateway\");\n                }\n                Err(e) => {\n                    if session_start.elapsed() >= self.success_threshold {\n                        log::debug!(\"Connection error after successful run: {e}\");\n                        return Ok(true);\n                    }\n                    anyhow::bail!(\"Connection error: {e}\");\n                }\n            };\n\n            let ts_init = clock.get_time_ns();\n\n            // Decode record\n            if let Some(msg) = record.get::<dbn::ErrorMsg>() {\n                handle_error_msg(msg);\n            } else if let Some(msg) = record.get::<dbn::SystemMsg>() {\n                if let Some(ack) = handle_system_msg(msg, ts_init) {\n                    self.send_msg(DatabentoMessage::SubscriptionAck(ack));","sourceCodeStart":748,"sourceCodeEnd":784,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/live.rs#L748-L784","documentation":"The Databento gateway closed the stream (record stream returned None) before the session reached the configured success_threshold duration. run_session treats a short-lived session as a failure and bails so the reconnection loop can restart it.","triggerScenarios":"The dbn record channel yields Ok(None) while session_start.elapsed() < self.success_threshold — gateway disconnect, idle timeout, or server-side session termination.","commonSituations":"Long-lived live sessions dropped by Databento, network instability causing gateway to end sessions, success_threshold set longer than the gateway's idle disconnect interval.","solutions":["Rely on the adapter's reconnect loop — the error signals a retry is warranted","Lower success_threshold so healthy short sessions are not treated as failures","Check Databento gateway status and network stability","Inspect logs for a pattern indicating server-side disconnects"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure success_threshold is realistic relative to gateway idle timeouts\nassert!(config.success_threshold < GATEWAY_IDLE_DISCONNECT_SECS);","typeGuard":null,"tryCatchPattern":"loop {\n    match session.run_session().await {\n        Ok(true) => break, // healthy session\n        Err(e) if e.to_string().contains(\"Session ended by gateway\") => {\n            warn!(\"gateway ended session, reconnecting\");\n            continue;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Keep reconnection logic enabled for live streaming","Set success_threshold sensibly vs expected session length","Monitor gateway disconnect frequency as a health signal"],"tags":["network","databento","disconnection","live-streaming"],"backgroundTag":"broken-pipe","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"}